String.PadLeftとは? わかりやすく解説

String.PadLeft メソッド (Int32)

このインスタンス内の文字右寄せし、指定した文字列文字数になるまで、左側空白埋め込みます。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function PadLeft ( _
    totalWidth As Integer _
) As String
Dim instance As String
Dim totalWidth As Integer
Dim returnValue As String

returnValue = instance.PadLeft(totalWidth)
public string PadLeft (
    int totalWidth
)
public:
String^ PadLeft (
    int totalWidth
)
public String PadLeft (
    int totalWidth
)
public function PadLeft (
    totalWidth : int
) : String

パラメータ

totalWidth

結果として生成される文字列文字数。これは、元の文字数と、埋め込み文字がある場合はその数を加えた数に等しくなります

戻り値
このインスタンス等価新しString。この新しインスタンスは文字右寄せされ、totalWidth長さになるまで左側空白埋め込まれています。または、totalWidth がこのインスタンス長さより短い場合は、このインスタンス等し新しString オブジェクト

例外例外
例外種類条件

ArgumentException

totalWidth が 0 未満です。

解説解説
使用例使用例

PadLeft メソッドコード例次に示します

Dim str As String
str = "BBQ and Slaw"
Console.WriteLine(str.PadLeft(15)) ' Displays "   BBQ and Slaw".
Console.WriteLine(str.PadLeft(5))  ' Displays "BBQ and Slaw".
String^ str = "BBQ and Slaw";
Console::WriteLine( str->PadLeft( 15 ) ); // Displays "   BBQ
 and Slaw".
Console::WriteLine( str->PadLeft( 5 ) );  // Displays "BBQ and
 Slaw".
var str : String;
str = "BBQ and Slaw";
Console.WriteLine(str.PadLeft(15)); // Displays "   BBQ and Slaw".
Console.WriteLine(str.PadLeft(5));  // Displays "BBQ and Slaw".
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.PadLeft メソッド (Int32, Char)

このインスタンス内の文字右寄せし、指定した文字列文字数になるまで、指定した Unicode 文字左側埋め込みます。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function PadLeft ( _
    totalWidth As Integer, _
    paddingChar As Char _
) As String
Dim instance As String
Dim totalWidth As Integer
Dim paddingChar As Char
Dim returnValue As String

returnValue = instance.PadLeft(totalWidth, paddingChar)
public string PadLeft (
    int totalWidth,
    char paddingChar
)
public:
String^ PadLeft (
    int totalWidth, 
    wchar_t paddingChar
)
public String PadLeft (
    int totalWidth, 
    char paddingChar
)
public function PadLeft (
    totalWidth : int, 
    paddingChar : char
) : String

パラメータ

totalWidth

結果として生成される文字列文字数。これは、元の文字数と、埋め込み文字がある場合はその数を加えた数に等しくなります

paddingChar

Unicode 埋め込み文字

戻り値
このインスタンス等価新しString。この新しインスタンスは文字右寄せされ、totalWidth長さになるまで左側paddingChar文字埋め込まれています。または、totalWidth がこのインスタンス長さより短い場合は、このインスタンス等し新しString

例外例外
例外種類条件

ArgumentException

totalWidth が 0 未満です。

使用例使用例

PadLeft メソッドコード例次に示します

Dim str As String
Dim pad As Char
str = "forty-two"
pad = "."c
Console.WriteLine(str.PadLeft(15, pad)) ' Displays "......forty-two".
Console.WriteLine(str.PadLeft(2,  pad)) ' Displays "forty-two".
String^ str = "forty-two";
Console::WriteLine( str->PadLeft( 15, L'.' ) ); // Displays "......forty-two".
Console::WriteLine( str->PadLeft( 2, L'.' ) );  // Displays "forty-two".
var str : String;
var pad : char;
str = "forty-two";
pad = ".";
Console.WriteLine(str.PadLeft(15, pad)) // Displays "......forty-two".
Console.WriteLine(str.PadLeft(2,  pad)) // Displays "forty-two".
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.PadLeft メソッド



このページでは「.NET Framework クラス ライブラリ リファレンス」からString.PadLeftを検索した結果を表示しています。
Weblioに収録されているすべての辞書からString.PadLeftを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からString.PadLeft を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「String.PadLeft」の関連用語

String.PadLeftのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.PadLeftのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS