您的位置:首页 > 其它

封装了一个通用的字符串模糊显示的扩展方法

2017-09-13 15:57 363 查看
public static class Ex
{
public static string DimString(this String source, int preLength, int lastLength, char symbol = '*')
{
string result = string.Empty;
if (source.Length > preLength && source.Length > lastLength)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < source.Length - preLength - lastLength; i++)
{
sb.Append(symbol);
}
result = source.Substring(0, preLength) + sb.ToString() + source.Substring(source.Length - lastLength, lastLength);
}

return result;
}
}


class Program
{
static void Main(string[] args)
{
string phone = "18515278888";
string result = phone.DimString(3, 4);

Console.ReadKey();
}
}


适用于模糊手机号、身份证号、银行卡号
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐