mask all digits except first 6 and last 4 digits of a string( length varies )

前端 未结 9 830
无人及你
无人及你 2021-01-01 14:26

I have a card number as a string, for example:

string  ClsCommon.str_CardNumbe r = \"3456123434561234\";

The length of this card number can

9条回答
  •  礼貌的吻别
    2021-01-01 15:03

    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 += " ";
    }
    

提交回复
热议问题