封装了一个通用的字符串模糊显示的扩展方法
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(); } }
适用于模糊手机号、身份证号、银行卡号
相关文章推荐
- [js高手之路] 跟GhostWu一起封装一个字符串工具库-扩展camelize与dasherize方法(3)
- [js高手之路] 跟GhostWu一起封装一个字符串工具库-扩展camelize与dasherize方法(3)
- [js高手之路] 跟GhostWu一起封装一个字符串工具库-扩展trim,trimLeft,trimRight方法(2)
- [js高手之路] 跟GhostWu一起封装一个字符串工具库-扩展字符串位置方法(4)
- Hibernate4 一个baseDao的封装,包含一些通用的增删改查方法
- .NET ->> 分享一个字符串模糊匹配指数的方法
- 【Log日志】一个封装的日志打印库(显示类,方法,行数)--破晓觉醒
- 字符串的原型扩展一个方法来解析url(String.prototype.pro)-自己写的一个方法
- C 封装一个通用链表 和 一个简单字符串开发库
- 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)
- 使用 MSIL 为 Enum.HasFlag 封装一个泛型的扩展方法
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- c# 超长字符串截取固定长度后显示...(超长后面显示点点点) 通用方法
- 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)
- 封装一个方法返回字符串出现最多的字符以及次数
- js封装一个出去字符串中的空格方法
- 一个通用的DataGridView导出Excel扩展方法(支持列数据格式化)
- Android自带播放器字符串显示乱码问题的一个解决方法
- 做swing程序中遇到使用消息提示框的,JOptionPane类其中封装了很多的方法。 很方便的,于是就简单的整理了一下。 1.1 showMessageDialog 显示一个带有OK 按钮的模态
- C#实现将一个字符串进行翻转显示的6种方法