c# - Curious about Format function with Phone Number -


update (solved): https://dotnetfiddle.net/6gejyo


i used following code format phone number in loop various formats:

string phonenumber = "9998675309" string.format("{0:" + formatstring + "}", convert.todouble(phonenumber)) 

i need format phone numbers 2 different ways. 1 came out expected , other did not.

so, curious, decided quick console app , see of different phone number formatting possibilities think of. here result:

http://i.imgur.com/pfklzfm.png

my question this: why of come out formatted way seem should , others not? there escape characters needed of them?

the "." has special meaning in format string. determines location of decimal separator in result string. have escape ".":

string formatstring = "###-###\\.####"; 

some examples of usage of "." in format strings:

// result "3.40" (3.4).tostring("#.00", cultureinfo.getcultureinfo("en-us"))  // result "3,142" (3.141592).tostring("#.000", cultureinfo.getcultureinfo("nl-nl")) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -