「VB.NET」PadLeftで文字列の左側を空白埋めする
構文
Public Function PadLeft (totalWidth As Integer) As String
指定された文字数になるまで左側に空白を埋め込むことで、このインスタンス内の文字を右寄せした新しい文字列を返します。
使用例
Module Module1
    Sub Main()
        'String型変数の定義
        Dim str As String = "study"
        Console.WriteLine(str + " 長さ: " + Len(str).ToString)
        '文字列の左側を空白埋める
        Dim res As String = str.PadLeft(8)
        Console.WriteLine(res + " 長さ: " + Len(res).ToString)
        Dim res2 As String = str.PadLeft(4)
        Console.WriteLine(res2 + " 長さ: " + Len(res2).ToString)
        Console.ReadKey()
    End Sub
End Module
実行結果
study 長さ: 5 study 長さ: 8 study 長さ: 5