45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using NPOI.SS.Formula.Functions;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace IRaCIS.Core.Application.Helper
|
||
{
|
||
public static class EmailMaskHelper
|
||
{
|
||
|
||
//显示位数:3分之2的位数,向上取整
|
||
//取哪几个个值:最后一位和前面几位
|
||
//其他:3个***。
|
||
//比如:hlj23@126.com
|
||
//为:hlj***3@126.com
|
||
|
||
//he@126.com
|
||
//为:h*** e@126.com
|
||
|
||
public static string MaskEmail(string email)
|
||
{
|
||
|
||
// 找到 "@" 符号的位置
|
||
int atIndex = email.IndexOf('@');
|
||
|
||
string visiblePartBefore = email.Substring(0, atIndex);
|
||
|
||
string afterAt = email.Substring(atIndex + 1);
|
||
|
||
int visibleLength = (int)Math.Ceiling((double)visiblePartBefore.Length * 2 / 3);
|
||
|
||
// 替换中间两位字符为星号
|
||
string hiddenPartBeforeAt = visiblePartBefore.Substring(0, visibleLength - 1) + "***" + visiblePartBefore.Last();
|
||
|
||
|
||
// 组合隐藏和可见部分
|
||
string hiddenEmail = hiddenPartBeforeAt + "@" + afterAt;
|
||
|
||
return hiddenEmail;
|
||
}
|
||
}
|
||
}
|