[英]How to format a number such that first 6 digits and last 4 digits are not hidden
How to format a number such that first 6 digits and last 4 digits are not hidden 如何格式化数字以使前6位和后4位不隐藏
such that 111111111111111 looks like 111111****1111 这样111111111111111看起来像111111 **** 1111
One simple way to do this is to slit the input.. 一种简单的方法是分割输入。
int number = 111111111111111;
string firstsix = number.ToString().Substring(0,6) //gets the first 6 digits
string middlefour = number.ToString().Substring(6,4) //gets the next 4
string rest = number.ToString().Substring(10, number.ToString().Lenght) //gets the rest
string combined = firstsix + "****" +rest;
You can also use LINQ, substituting chars with indexes more than 5 and less than number.Length - 4
with *
: 您也可以使用LINQ,用索引大于5且小于
number.Length - 4
char替换number.Length - 4
*
number.Length - 4
的*
:
string number = "111111111111111";
string res = new string(number.Select((c, index) => { return (index <= 5 || index >= number.Length - 4) ? c : '*'; }).ToArray());
Console.WriteLine(res); // 111111*****1111
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.