Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a string containing 16 digits into 4 groups

Tags:

string

c#

.net

If you take a look at the plastic in your wallet the 16 digit credit card number is broken into 4 groups of 4. Im trying to do the same thing,

Currently I have a string that has 16 digits but is formed as 1 single number. How can I add a " " after the 4th 8th & 12th number?

Any tips would be really helpful.

Thanks

like image 513
Diver Dan Avatar asked May 31 '26 22:05

Diver Dan


1 Answers

var number = 1234567890123456;
number.ToString( "0000-0000-0000-0000" );
like image 91
Thomas Avatar answered Jun 03 '26 13:06

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!