These methods enable you to justify a string so that it is left- or right-justified. As with substring, the PadLeft and PadRight methods are overloaded. The first version of these methods requires only a maximum length of the String, and then uses spaces to pad the String. The other version requires two parameters: the length of the returned String and the character that should be used to pad the original String:
Dim padString = "Padded Characters"
TextBoxi.Text &= padString.PadLeft("30") & Environment.NewLine TextBoxi.Text &= padString.PadRight("3 0", "_") &
Environment.NewLine TextBoxi.Text &= line & Environment.NewLine
Figure 2-8 shows the same string first with the left padded with spaces, then with the right padded with underscores. Note that because the default font on this screen isn't fixed size, the spaces are compacted and the two strings do not appear as the same length.
Was this article helpful?