Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a Social Security Number (SSN) as XXX-XX-XXXX from XXXXXXXXX

Tags:

I am getting a social security number (SSN) from a data warehouse. While posting it to a CRM I want it to be formatted like XXX-XX-XXXX instead of XXXXXXXXX.

It's like converting a simple string with dashes at positions 4 and 7. I am pretty new to C#, so what is the best way to do this?

like image 712
Ashutosh Avatar asked Nov 08 '10 21:11

Ashutosh


1 Answers

For a simple, short, and self commenting solution, try:

String.Format("{0:000-00-0000}", 123456789) 

123456789 representing your SSN variable.

like image 154
George Johnston Avatar answered Oct 08 '22 00:10

George Johnston