开发者

mask account number with string.format

I have a bank account number that is variable length.

1234567890123
0987654321

I want to mask the account number for viewing, except for the last 4 digits.

XXXXXXXXX0123
XXXXXX4321

Is there a way to make it mask all the numbers but the last 4 using String.Format w开发者_如何学Pythonithout using Substring to pull out the last 4?

EDIT:

There's nothing wrong with substring. I'm just looking to see if there is a simple formatting string to convert all but the last 4 characters into something else.


What's wrong with using substring?

However, if you put the number in a long (needed to hold all the digits), you could do number % 10000 to extract the last four digits, and a fixed string for the XXX...

Answering the literal wording of the question, rather than what you probably really meant :) you could implement a custom formatter to printed masked account numbers, and then there would be a 'simple format string' that printed things in the way you want

The second example on this page formats (all the digits of) an account number. It could be modified to print a masked version instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜