mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-29 04:37:01 +08:00
手机号邮箱等mask
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Version>2.2.8.6</Version>
|
||||
<Version>2.2.8.7</Version>
|
||||
<Authors>懒得勤快</Authors>
|
||||
<Company>masuit.com</Company>
|
||||
<Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
|
||||
|
||||
@@ -1280,10 +1280,43 @@ namespace Masuit.Tools
|
||||
/// <param name="where"></param>
|
||||
public static void RemoveWhere<T>(this ICollection<T> @this, Func<T, bool> @where)
|
||||
{
|
||||
foreach (var obj in @this.Where(@where).ToList())
|
||||
foreach (var obj in @this.Where(where).ToList())
|
||||
{
|
||||
@this.Remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串掩码
|
||||
/// </summary>
|
||||
/// <param name="s">字符串</param>
|
||||
/// <param name="mask">掩码符</param>
|
||||
/// <returns></returns>
|
||||
public static string Mask(this string s, char mask = '*')
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s?.Trim()))
|
||||
{
|
||||
return s;
|
||||
}
|
||||
s = s.Trim();
|
||||
string masks = new string(new[] { mask, mask, mask, mask });
|
||||
return s.Length switch
|
||||
{
|
||||
_ when s.Length > 4 => Regex.Replace(s, "(\\w{3})\\w+(\\w{4})", $"$1{masks}$2"),
|
||||
_ when s.Length >= 2 && s.Length <= 4 => Regex.Replace(s, "(\\w{1})\\w*(\\w{1})", $"$1{masks}$2"),
|
||||
_ => s + masks
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱掩码
|
||||
/// </summary>
|
||||
/// <param name="s">邮箱</param>
|
||||
/// <param name="mask">掩码</param>
|
||||
/// <returns></returns>
|
||||
public static string MaskEmail(this string s, char mask = '*')
|
||||
{
|
||||
return !MatchEmail(s) ? s : s.Replace(s.Substring(0, s.LastIndexOf("@")), Mask(s.Substring(0, s.LastIndexOf("@")), mask));
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
<!--*-->
|
||||
<id>Masuit.Tools.Net</id>
|
||||
<!--*-->
|
||||
<version>2.2.8.5</version>
|
||||
<version>2.2.8.7</version>
|
||||
<title>Masuit.Tools</title>
|
||||
<!--*-->
|
||||
<authors>masuit.com</authors>
|
||||
|
||||
Reference in New Issue
Block a user