asp.net mvc - MVC/C# Put a comma after every number in string -


i have string of 4 numbers:

1234

i want convert in elegant way possible in mvc to

1,2,3,4

i've tried this:

codetosend.tostring("#,#");

but outputs "1,234" (which expected really).

i suspected following put comma after every digit, no avail.

codetosend.tostring("#,#,#,#");

i have tried string.format, again facing same issue.

var formattedstring = string.format("{0:0,0}", 1234);

whats efficient way of doing therefore?

note: string of numbers 4 digits long - , numbers only. don't want use insert wouldn't elegant imo , aware question has been asked before in similar ways different in crucial ways (such formatting thousands, not every digit or not elegantly!).

how using string.join?

int = 1234; string.join(",", i.tostring().tochararray()); // 1,2,3,4 

if 1234 string, use;

string s = "1234"; string.join(",", s.tochararray()); // 1,2,3,4 

or

string s = "1234"; string.join(",", s.tolist()); // 1,2,3,4 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -