Andy,
Look up "Numeric Format Strings" in the online help, specifically "Custom
Numeric Format Strings", you will see that # is a digit placeholder, while 0
is the zero placeholder, if you want zeros to appear in your formatted
string use 0 instead of #. Something like:
[color=blue]
> Dim strNumber as string = "08701218300"
> Dim strFormattedNumber as String = CLng(strNumber).ToString("0000 000[/color]
0000")
http://msdn.microsoft.com/library/de...ngoverview.asp http://msdn.microsoft.com/library/de...matstrings.asp
Hope this helps
Jay
"AndyBarker" <andy.barker@icm-computer.co.uk> wrote in message
news:40865e73$1@news.netserv.net...[color=blue]
> What if the phone number begins with a 0 like most do here in the uk.
>
> Dim strNumber as string = "08701218300"
> Dim strFormattedNumber as String = CDbl(strNumber).ToString("#### ###[/color]
####")[color=blue]
> would return 870 121 8300
>
> Regards
>
> Andy
>
>
> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
> news:%23kQDaiyJEHA.3596@tk2msftngp13.phx.gbl...[color=green]
> > Hi,
> >
> > Dim strPhone As String = "9999999999"
> >
> > Dim strFormatedNumber As String = CLng(strPhone).ToString("(###)[/color]
> ###-####")[color=green]
> > Debug.WriteLine(strFormatedNumber)
> >
> > Ken
> > -------------------
> > "Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
> > news:wfp5zwo0xcv2$.3024n5vkon65$.dlg@40tude.net...[color=darkred]
> > >I have a table in the database with a phone number field. The phone[/color][/color]
> number[color=green][color=darkred]
> > > is stored without any punctuation (e. g. 9995551234). I wish to take[/color][/color]
> that[color=green][color=darkred]
> > > string and format it for display (e. g. (999) 555-1234).
> > >
> > > I know that I can use the .substring method of the string class to get[/color][/color]
> the[color=green][color=darkred]
> > > characters I want and format it:
> > >
> > > Dim s As String
> > >
> > > With strPhone
> > > s = "(" & .Substring(0,3) & ") " & .SubString(3,3) & "-" &[/color][/color]
> .Substring(6,4)[color=green][color=darkred]
> > > End With
> > >
> > >
> > > While this works, it seems a bit lengthy plus, what if I need to use a
> > > different substring format for other string that I want to display?
> > >
> > > I created a class called SubFormat that implements the IFormatProvider[/color][/color]
> and[color=green][color=darkred]
> > > ICustomFormatter interfaces. I can use this class with String.Format[/color][/color]
> like[color=green][color=darkred]
> > > so:
> > >
> > > s = String.Format(New SubFormat(),"({0:S0,3})[/color][/color]
> {0:S3,3}-{0:S6,4}",strPhone)[color=green][color=darkred]
> > >
> > > The "S" is my custom format specificer. The 0,3 means start at index[/color][/color][/color]
0[color=blue]
> in[color=green][color=darkred]
> > > the string and get the next 3 characters.
> > >
> > > This also works and it can work with any string and format I wish.
> > >
> > > My question (after that long post) is if I have re-invented the wheel.
> > > Does this sort of functionality already exist?
> > >
> > > I couldn't find it.
> > >
> > > Thanks,
> > >
> > >
> > > --
> > > Chris
> > >
> > > To send me an E-mail, remove the underscores and lunchmeat from my[/color][/color]
> E-Mail[color=green][color=darkred]
> > > address.[/color]
> >
> >[/color]
>
>[/color]