|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Format function... Confused!I have a string that contains a number eg 11 that I want to format into a 4 character string with leading zeros ie 0011 I guess I need to use the "format" function.... ie newstring=format(oldstring,"????") What goes in as the format conversion to get the affect I want? Thanks in advance Simon -- ================================ Simon Verona Dealer Management Service Ltd Stewart House Centurion Business Park Julian Way Sheffield S9 1GD Tel: 0870 080 2300 Fax: 0870 735 0011 Hi,
Try Format(oldstring, "0000"). For more information refer to the "User-defined Numeric Formats" topic of the Format function. Regards, Cerebrus. Simon Verona wrote:
<snip> > I have a string that contains a number eg 11 that I want to format into a 4 <snip>> character string with leading zeros ie 0011 > > I guess I need to use the "format" function.... ie > newstring=format(oldstring,"????") Instead of Format, you may use PadLeft method of the String type: NewString = OldString.PadLeft(4, "0"c) This will return a string with 4 or less "0" to the left: "1" -> "0001"; "12" -> "0012", etc. Regards, Branco. PadLeft
Dim i As Integer = 11 Trace.WriteLine(i.ToString.PadLeft(4, "0"c)) Show quoteHide quote "Simon Verona" <nom***@nomail.zzz> wrote in message news:%239C0Z5WVGHA.5248@TK2MSFTNGP10.phx.gbl... > I'm a little confused > > I have a string that contains a number eg 11 that I want to format into a > 4 character string with leading zeros ie 0011 > > I guess I need to use the "format" function.... ie > newstring=format(oldstring,"????") > > What goes in as the format conversion to get the affect I want? > > Thanks in advance > Simon > > -- > ================================ > Simon Verona > Dealer Management Service Ltd > Stewart House > Centurion Business Park > Julian Way > Sheffield > S9 1GD > > Tel: 0870 080 2300 > Fax: 0870 735 0011 > > Oh, let me try, too :)
Dim i As Integer = 11 Dim s As String = i.ToString("d4") Kelly Show quoteHide quote "Simon Verona" <nom***@nomail.zzz> wrote in message news:%239C0Z5WVGHA.5248@TK2MSFTNGP10.phx.gbl... > I'm a little confused > > I have a string that contains a number eg 11 that I want to format into a > 4 character string with leading zeros ie 0011 > > I guess I need to use the "format" function.... ie > newstring=format(oldstring,"????") > > What goes in as the format conversion to get the affect I want? > > Thanks in advance > Simon > > -- > ================================ > Simon Verona > Dealer Management Service Ltd > Stewart House > Centurion Business Park > Julian Way > Sheffield > S9 1GD > > Tel: 0870 080 2300 > Fax: 0870 735 0011 > >
Option Strict On
disabling controls by checking off a radio button when the form loads Currently logged in user's email Check Interface Implementation of a Type SENDMail Get a simple handler Invoking CTRL+C,X,V programatically Double-Buffering in VB2005? save string var to html file without losing format Clearing data from a DataGrid |
|||||||||||||||||||||||