c# - How can I use placeholders for characters in a string? -


i trying use solution provided in this answer, , have referenced this article.

basically, trying format social security number. method used in articles linked above:

string.format(“{0:###-##-####}”, 123456789); 

this works great when number passed in shown above, number need format contained in string - doing (which doesn't work):

string.format(“{0:###-##-####}”, "123456789"); 

what way around problem?

you can parse string numeric type , use string.format like:

string.format("{0:###-##-####}", long.parse("123456789")); 

you can use long.tryparse or int.tryparse based on number, , use value in string.format.

long number; string str = "123456789"; if (!long.tryparse(str, out number)) {     //invalid number }  string formattedstr = string.format("{0:###-##-####}", number); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -