Formatting string to phone number...
I simple way to format a string to a phone number is by doing to following:
double result = default(double);
if (double.TryParse(from.PhoneNumber, out result))
{
to.PhoneNumber = string.Format("{0: (###) ###-####}", result);
}
This format will "9908675309" to "(990) 867-5309". In order for the string formatting to work the string to be formatted must be converted to a decimal data type.
Now, I'll admit, there are many ways to skin the proverbial cat (like using a regular expression)...but this is just another way of doing this...
Comments