String format, minimum width.

  • Thread starter Thread starter Jameson
  • Start date Start date
J

Jameson

Hi,

Dumb question for you:

Is there a quick and easy way to ensure a string has a minimum width using
format specifier?

Should I just write

if myString.Length < 8 then myString.PadLeft ( ...... )

?

Thanks
 
Should I just write
if myString.Length < 8 then myString.PadLeft ( ...... )

?

No need to check the length first, PadLEft does that for you. Just do

myString = myString.PadLeft(8)

What do you mean by format specifier? Do you get myString from a call
to String.Format or some other formatting method?


Mattias
 
Hi,

Dumb question for you:

Is there a quick and easy way to ensure a string has a minimum width using
format specifier?

Should I just write

if myString.Length < 8 then myString.PadLeft ( ...... )

?

Thanks

In case you want to use string.format...

dim sMessage as string = string.format("{0,-8}", value)

If value is less then 8 characters, the result will be an 8 character
string left padded with spaces. To right pad, make the value after
the comma a positive number.

HTH
 
Back
Top