How do you right align using .ToString()
-
I'm just stuck here ... Given:
Dim i As Integer = 1
Debug.Print(i.ToString("000")) ' This give me 2 leading zeros followed by the number 1; not what I want
What I can't seem to figure out is the correct format string to be used with .ToString to give me two spaces then the number 1. (which would be right aligned)
-
I'm just stuck here ... Given:
Dim i As Integer = 1
Debug.Print(i.ToString("000")) ' This give me 2 leading zeros followed by the number 1; not what I want
What I can't seem to figure out is the correct format string to be used with .ToString to give me two spaces then the number 1. (which would be right aligned)
I use
string.PadLeft()
to right-align some text... :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I'm just stuck here ... Given:
Dim i As Integer = 1
Debug.Print(i.ToString("000")) ' This give me 2 leading zeros followed by the number 1; not what I want
What I can't seem to figure out is the correct format string to be used with .ToString to give me two spaces then the number 1. (which would be right aligned)
Composite formatting using indexed placeholders
"{0}"
allows for alignment but standard formatting with the ToString method does not. Example of alignment in a fixed width fieldConsole.WriteLine("{0, -4}", 99); // "99 "
Console.WriteLine("{0, 4}", 99); // " 99"Debug.Print has an overload for composite formatting so you can do the same trick. Alan.
-
I use
string.PadLeft()
to right-align some text... :)Luc Pattyn [My Articles] Nil Volentibus Arduum
PadLeft is the winner. Just what I was looking to do. Thanks, david
-
Composite formatting using indexed placeholders
"{0}"
allows for alignment but standard formatting with the ToString method does not. Example of alignment in a fixed width fieldConsole.WriteLine("{0, -4}", 99); // "99 "
Console.WriteLine("{0, 4}", 99); // " 99"Debug.Print has an overload for composite formatting so you can do the same trick. Alan.
String.Format will do what you want for creating strings.
-
I'm just stuck here ... Given:
Dim i As Integer = 1
Debug.Print(i.ToString("000")) ' This give me 2 leading zeros followed by the number 1; not what I want
What I can't seem to figure out is the correct format string to be used with .ToString to give me two spaces then the number 1. (which would be right aligned)