Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format String as phone number in C#

Tags:

c#

I have a string value 1233873600 in C# and I have to convert it to 123-387-7300 in C#

Is there any in-built function which will do that in c#?

like image 400
acadia Avatar asked Jan 20 '11 14:01

acadia


2 Answers

Cast your string to a long and use the format "{0:### ### ####}";

string.Format("{0:(###) ###-####}", 1112223333);
like image 146
hunter Avatar answered Oct 20 '22 17:10

hunter


string phone = "1233873600".Insert(6, "-").Insert(3, "-");
like image 43
Greg Avatar answered Oct 20 '22 18:10

Greg