Gup3rSuR4c
Gup3rSuR4c

Reputation: 9488

How to String.Format an Int64 into an 'obfuscated' string (for a Credit Card) C#?

Say I have an Int64 = 1234567890123456 (and we assume its a valid number), how can I format it into 1••• •••• •••• 3456?

I've tried String.Format("{0:#••• •••• •••• ####}") and String.Format("{0:0••• •••• •••• 0000}") and both of them produce 123456789012••• •••• •••• 3456 which is wrong and completely defeats the point of obfuscating the number...

I'd appreciate some guidance. Thanks in advance!

Upvotes: 0

Views: 608

Answers (1)

William Mioch
William Mioch

Reputation: 917

Wouldn't it be easier to just convert it to a string and fill in the specific chars?

string strNum = num.ToString().PadLeft(16,'0');
for(int i = 1; i < 12; i++) strNum[i] = '*';

something along those lines?

Upvotes: 2

Related Questions