469,271 Members | 1,711 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

What is the best way to format a phone number

I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.
Nov 21 '05 #1
6 16681
Do you need it for London. Paris, Lyon or for Amsterdam?

To show you that this can be even different for cities.
AS far as I know is this not in the globalization. so you have to write it
yourself however there are lot of samples how to do it by instance for the
US on Internet..

I hope this helps,

Cor
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Nov 21 '05 #2
* "KFactor" <kf******@hotmail.com> scripsit:
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?


I assume that you will have to format the number yourself. Phone
numbers are very specific to countries.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3
I was trying to reproduce the functionality VB6 has. In VB6 you can simply
use:
format("1234567890","(###) ###-####").

I was wondering if there is something similar in dot net.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Do you need it for London. Paris, Lyon or for Amsterdam?

To show you that this can be even different for cities.
AS far as I know is this not in the globalization. so you have to write it
yourself however there are lot of samples how to do it by instance for the
US on Internet..

I hope this helps,

Cor
I would like to convert a 10-digit string phone number (1234567890) to say (xxx) xxx-xxxx. Is there a function for this or should I write the code to piece together one character at a time?


Nov 21 '05 #4
Dim Phone As String = "1234567890"

Label1.Text = Phone.ToString.Format("({0}) {1}-{2}", Phone.Substring(0, 3),
Phone.Substring(3, 3), Phone.Substring(6, 4))

I'n not sure this best way

"KFactor" <kf******@hotmail.com> schreef in bericht
news:Oa**************@TK2MSFTNGP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.

Nov 21 '05 #5
KFactor,
Unfortunately .NET does not allow formatting of strings like VB6 does.

In addition to the other comments, what I normally do is convert the phone
number into a number (integer) then use a custom format on the integer.
Something like:

Dim phoneNumber As String = "1234567890"
phoneNumber = Cint(phoneNumber).ToString("(000) 000-0000")

Alternatively you might be able to create a ICustomFormatter object (an
object that implements Syste.ICustomFormatter.

Hope this helps
Jay

"KFactor" <kf******@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say
(xxx) xxx-xxxx. Is there a function for this or should I write the code to
piece together one character at a time?

Any suggestions is appreciated.

Nov 21 '05 #6
Thanks Jay,

This is exactly what I was looking for.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
KFactor,
Unfortunately .NET does not allow formatting of strings like VB6 does.

In addition to the other comments, what I normally do is convert the phone
number into a number (integer) then use a custom format on the integer.
Something like:

Dim phoneNumber As String = "1234567890"
phoneNumber = Cint(phoneNumber).ToString("(000) 000-0000")

Alternatively you might be able to create a ICustomFormatter object (an
object that implements Syste.ICustomFormatter.

Hope this helps
Jay

"KFactor" <kf******@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP15.phx.gbl...
I would like to convert a 10-digit string phone number (1234567890) to say (xxx) xxx-xxxx. Is there a function for this or should I write the code to piece together one character at a time?

Any suggestions is appreciated.


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sansanee | last post: by
6 posts views Thread by Poewood | last post: by
3 posts views Thread by Eddy Soeparmin | last post: by
9 posts views Thread by julie.siebel | last post: by
2 posts views Thread by jeswin12 | last post: by
6 posts views Thread by JFB | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.