>
Composite formatting
 Sub Main()
      Dim i1() = {5, 55, 55555}
      Dim idx As Integer
      Dim d1() = {3.4455, 27.3334567, 300000.000007}
      Dim s1() = {"String1", "String2 and more", "String3 and even more"}
      Dim output As String
      Console.WriteLine("No formatting")
      For idx = 0 To 2
         output = String.Format("{0} {1} {2}", i1(idx), d1(idx), s1(idx))
         Console.WriteLine(output)
      Next
      Console.WriteLine(vbCrLf)
      Console.WriteLine("Alignment formatting to right, positive 
      alignment parameter")
      For idx = 0 To 2
         output = String.Format("{0,8} {1,14} {2,26}", i1(idx), _
         d1(idx), s1(idx))
         Console.WriteLine(output)
      Next
      Console.WriteLine(vbCrLf)
      Console.WriteLine("Alignment formatting to left, negative _
      alignment parameter")
      For idx = 0 To 2
         output = String.Format("{0,-8} {1,-14} {2,-26}", _
         i1(idx), d1(idx), s1(idx))
         Console.WriteLine(output)
      Next
      Console.WriteLine(vbCrLf)
      Console.WriteLine("Alignment formatting to left, with _
      number formatting, index #1 used twice: _
      F3: floating point and C: Currency")
      For idx = 0 To 2
         output = String.Format("{0,-8:d6} {1,-14:F3} _
          {1,-14:C} {2,-26}", i1(idx), d1(idx), s1(idx))
         Console.WriteLine(output)
      Next
      Console.ReadLine()
   End Sub
  

Notice the difference in using the alignment parameter and not having it. Also notice the negative and positive alignment formatter.

Finally notice the other formatters such as D(number) which will add leading zeros, F(number) which will format for the number of positions to right of decimal point, and C for currency which automatically formats for dollars and cents (US) and $ sign If you have a different culture setup this will be different.

10/12/2015
TheLonelyProgrammer.Net
Alone in a sea of non-programmers
Home Composite Formatting ToString Formatting