I have a simple question about how to format a string.
I have this number as a string “01234567890”, with zero on left, and need to format that to be like that “012.345.678-90“.
I solved it using it
char[] charArgs = sCPF.ToCharArray();
return String.Format("{0}{1}{2}.{3}{4}{5}.{6}{7}{8}-{9}{10}",
charArgs[0], charArgs[1], charArgs[2], charArgs[3],
charArgs[4], charArgs[5], charArgs[6], charArgs[7],
charArgs[8], charArgs[9], charArgs[10]);
I also tried that :
Convert.ToInt64("01234567890").ToString("000.000.000-00")
but that gives me “1234567890,000000-00”
But if I also tried this
Convert.ToInt64("01234567890").ToString("000-000-000-00")
which results in “012-345-678-90”, but is not what I need in this case, where I need the dots (.).
Are there a better way to do it?
I am using .net 2.0.
You were almost there.
Try this:
That gives me:
012.345.678-90