String.Format using a variable

zekeman

Well-known member
Joined
May 23, 2006
Messages
224
Programming Experience
10+
Using the string.format I can type:

VB.NET:
String.Format("{0,-10}", "Field")
   Or
String.Format("{0,-10}", MyValue)

CAN I replace the 10 above with a variable and how?
 
The pattern string is a string you can build up like any other string.
VB.NET:
Dim variable As Integer = 22
Dim fmt As String = "{0," & variable.ToString() & "}"
Dim s As String = String.Format(fmt, param)
 
Back
Top