String Formatting Question

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

I have a string contains a phone number like "4164851412"
What would be the easiest way to format the string into phone number format
like "(416) 485-1412"

Thank you,
Alan
 
A.M said:
I have a string contains a phone number like "4164851412"
What would be the easiest way to format the string into phone number format
like "(416) 485-1412"

First, make sure that the length of the string is 10, then do:

String.Format ("({0}) {1}-{2}", number.Substring(0, 3),
number.Substring(3, 3),
number.Susbtring(6, 4));
 
Thank you Jon.
Jon Skeet said:
First, make sure that the length of the string is 10, then do:

String.Format ("({0}) {1}-{2}", number.Substring(0, 3),
number.Substring(3, 3),
number.Susbtring(6, 4));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top