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

前端 未结 9 884
无人及你
无人及你 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 14:38

    Linq saves coding lines, small code snippet.

    Replaces with (*) char above 6 and bellow CardPan length minus 4

    var CardPan = "1234567890123456";
    var maskedPan = CardPan.Aggregate(string.Empty, (value, next) =>
    {
        if (value.Length >= 6 && value.Length < CardPan.Length - 4)
        {
            next = '*';
        }
        return value + next;
    });
    

提交回复
热议问题