【.NET】*打星号(隐藏部分)

描述:支持多个电话;

//隐藏部分内容,支持一个值有多个联系方式,用逗号隔开。
//参数:value - 值,subIndex - 从第几位开始,subQty - 隐藏几位数
protected string getLX_rep(string value,int subIndex, int subQty) { int minLength = Math.Abs(subIndex) + Math.Abs(subQty) + 1; string temp = ""; string[] v_array = value.Split(new char[]{',',''});//英文和拼音的逗号。 if (value.Length >= minLength) { if (v_array.Length > 1)//有多个 {   for(int i=0;i<v_array.Length;i++)   {     temp += (v_array[i].Length > minLength) ? v_array[i].Replace(v_array[i].Substring(subIndex, subQty), "****") : "****";     if(v_array.Length-1 > i)     {       temp += ",";     }   } } else {   temp = value.Replace(value.Substring(subIndex, subQty), "****"); } } else { temp = (value.Length != 0) ? "****" : ""; } return temp; }

原理:很简单,就是替换掉从值里截取几个字符,然后换成星号。

原文地址:https://www.cnblogs.com/laokchen/p/5752210.html