I have a card number as a string, for example:
string ClsCommon.str_CardNumbe r = \"3456123434561234\";
The length of this card number can
One method:
string masked = null; for (int i = 0; i < str_CardNumber.Length; i++) { masked += (i > 5 && i < str_CardNumber.Length - 4) ? 'X' : str_CardNumber[i]; if ((i + 1) % 4 == 0) masked += " "; }