このインスタンス内の文字を右寄せし、指定した文字列の文字数になるまで、指定した Unicode 文字を左側に埋め込みます。
Overloads Public Function PadLeft( _
ByVal totalWidth As Integer, _ ByVal paddingChar As Char _) As String
[C#]
public string PadLeft(inttotalWidth,charpaddingChar);
[C++]
public: String* PadLeft(inttotalWidth,__wchar_tpaddingChar);
[JScript]
public function PadLeft(
totalWidth : int,paddingChar : Char) : String;
パラメータ
- totalWidth
結果として生成される文字列の文字数。これは、元の文字数と、埋め込み文字がある場合はその数を加えた数に等しくなります。 - paddingChar
Unicode 埋め込み文字。
戻り値
このインスタンスと等価な新しい String 。この新しいインスタンスでは文字が右寄せされ、 totalWidth の長さになるまで左側に paddingChar の文字が埋め込まれています。
または totalWidth がこのインスタンスの長さより短い場合は、このインスタンスと等しい新しい String 。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | totalWidth が 0 未満です。 |
使用例
[Visual Basic, C++, JScript] 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".
[C++]
String *str = L"forty-two";
Console::WriteLine(str-> PadLeft(15, L'.')); // Displays "......forty-two".
Console::WriteLine(str-> PadLeft(2, L'.')); // Displays "forty-two".
[JScript]
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".
[C#] C# のサンプルはありません。Visual Basic、C++、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
String クラス | String メンバ | System 名前空間 | String.PadLeft オーバーロードの一覧 | Char | Int32 | PadRight | Trim