Alex Rivera | Logout

formatting string in MVC /C#

Asked 2011-04-01T10:02:54.713
15

I have a string 731478718861993983 and I want to get this 73-1478-7188-6199-3983 using C#. How can I format it like this ?

Thanks.

Edit
Report

1 Answer

0

If the position of "-" is always the same then you can try

string s = "731478718861993983";
s = s.Insert(2, "-");
s = s.Insert(7, "-");
s = s.Insert(12, "-");
s = s.Insert(17, "-"); 
answered 2011-04-01T10:17:29.943

Your Answer