次の方法で共有


String.PadLeft メソッド (Int32)

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

Overloads Public Function PadLeft( _
   ByVal totalWidth As Integer _) As String
[C#]
public string PadLeft(inttotalWidth);
[C++]
public: String* PadLeft(inttotalWidth);
[JScript]
public function PadLeft(
   totalWidth : int) : String;

パラメータ

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

戻り値

このインスタンスと等価な新しい String 。この新しいインスタンスでは文字が右寄せされ、 totalWidth の長さになるまで左側に空白が埋め込まれています。

または totalWidth がこのインスタンスの長さより短い場合は、このインスタンスと等しい新しい String。

例外

例外の種類 条件
ArgumentException totalWidth が 0 未満です。

解説

Unicode の空白文字は、16 進数で 0x20 と定義されています。

使用例

[Visual Basic, C++, JScript] 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".

[C++] 
String *str = L"BBQ and Slaw";
Console::WriteLine(str->PadLeft(15)); // Displays "   BBQ and Slaw".
Console::WriteLine(str->PadLeft(5));  // Displays "BBQ and Slaw".

[JScript] 
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".

[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 オーバーロードの一覧 | Int32 | PadRight | Trim