String.PadRight メソッド

定義

現在の文字列の末尾に空白または指定された Unicode 文字が埋め込まれた指定された長さの新しい文字列を返します。

オーバーロード

PadRight(Int32)

指定された文字数になるまで右側に空白を埋め込むことで、この文字列内の文字を左寄せした新しい文字列を返します。

PadRight(Int32, Char)

指定された文字数になるまで右側に指定された Unicode 文字を埋め込むことで、この文字列内の文字を左寄せした新しい文字列を返します。

PadRight(Int32)

Source:
String.Manipulation.cs
Source:
String.Manipulation.cs
Source:
String.Manipulation.cs

指定された文字数になるまで右側に空白を埋め込むことで、この文字列内の文字を左寄せした新しい文字列を返します。

public:
 System::String ^ PadRight(int totalWidth);
public string PadRight (int totalWidth);
member this.PadRight : int -> string
Public Function PadRight (totalWidth As Integer) As String

パラメーター

totalWidth
Int32

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

戻り値

このインスタンスと等価な新しい文字列。ただし左揃えであり、totalWidth の長さになるまで右側に空白が埋め込まれています。 ただし、totalWidth がこのインスタンスの長さより短い場合、メソッドは既存のインスタンスへの参照を返します。 totalWidth がこのインスタンスの長さと等しい場合、メソッドはこのインスタンスと同一の新しい文字列を返します。

例外

totalWidth が 0 未満です。

PadRightメソッドの例を次に示します。

String^ str = "BBQ and Slaw";
Console::Write( "|" );
Console::Write( str->PadRight( 15 ) );
Console::WriteLine( "|" ); // Displays "|BBQ and Slaw   |".
Console::Write( "|" );
Console::Write( str->PadRight( 5 ) );
Console::WriteLine( "|" ); // Displays "|BBQ and Slaw|".
string str;
str = "BBQ and Slaw";

Console.Write("|");
Console.Write(str.PadRight(15));
Console.WriteLine("|");       // Displays "|BBQ and Slaw   |".

Console.Write("|");
Console.Write(str.PadRight(5));
Console.WriteLine("|");       // Displays "|BBQ and Slaw|".
let str = "BBQ and Slaw"

printf "|"
printf $"{str.PadRight 15}"
printfn "|"       // Displays "|BBQ and Slaw   |".

printf "|"
printf $"{str.PadRight 5}"
printfn "|"       // Displays "|BBQ and Slaw|".
Dim str As String
str = "BBQ and Slaw"

Console.Write("|")
Console.Write(str.PadRight(15))
Console.WriteLine("|") ' Displays "|BBQ and Slaw   |".

Console.Write("|")
Console.Write(str.PadRight(5))
Console.WriteLine("|") ' Displays "|BBQ and Slaw|".

注釈

Unicode スペースは、16 進数の0x0020として定義されます。

メソッドは PadRight(Int32) 、返された文字列の末尾を埋め込みます。 つまり、右から左の言語で使用すると、文字列の左側の部分が埋め込まれます。

注意

メソッドが PadRight 現在のインスタンスに空白文字を埋め込む場合、このメソッドは現在のインスタンスの値を変更しません。 代わりに、末尾の空白が埋め込まれた新しい文字列が返され、その合計の長さが totalWidth 文字になります。

こちらもご覧ください

適用対象

PadRight(Int32, Char)

Source:
String.Manipulation.cs
Source:
String.Manipulation.cs
Source:
String.Manipulation.cs

指定された文字数になるまで右側に指定された Unicode 文字を埋め込むことで、この文字列内の文字を左寄せした新しい文字列を返します。

public:
 System::String ^ PadRight(int totalWidth, char paddingChar);
public string PadRight (int totalWidth, char paddingChar);
member this.PadRight : int * char -> string
Public Function PadRight (totalWidth As Integer, paddingChar As Char) As String

パラメーター

totalWidth
Int32

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

paddingChar
Char

Unicode 埋め込み文字。

戻り値

このインスタンスと等価な新しい文字列。ただし左揃えであり、totalWidth の長さになるまで右側に paddingChar の文字が埋め込まれています。 ただし、totalWidth がこのインスタンスの長さより短い場合、メソッドは既存のインスタンスへの参照を返します。 totalWidth がこのインスタンスの長さと等しい場合、メソッドはこのインスタンスと同一の新しい文字列を返します。

例外

totalWidth が 0 未満です。

PadRightメソッドの例を次に示します。

String^ str = "forty-two";
Console::Write( "|" );
Console::Write( str->PadRight( 15, '.' ) );
Console::WriteLine( "|" ); // Displays "|forty-two......|".
Console::Write( "|" );
Console::Write( str->PadRight( 5, '.' ) );
Console::WriteLine( "|" ); // Displays "|forty-two|".
string str = "forty-two";
char pad = '.';

Console.WriteLine(str.PadRight(15, pad));    // Displays "forty-two......".
Console.WriteLine(str.PadRight(2,  pad));    // Displays "forty-two".
let str = "forty-two"
let pad = '.'

printfn $"{str.PadRight(15, pad)}"    // Displays "forty-two......".
printfn $"{str.PadRight(2, pad)}"    // Displays "forty-two".
Dim str As String
Dim pad As Char
str = "forty-two"
pad = Convert.ToChar(".") 
Console.WriteLine(str.PadRight(15, pad)) ' Displays "|forty-two......|".
Console.WriteLine(str.PadRight(2,  pad)) ' Displays "|forty-two|".

注釈

メソッドは PadRight(Int32, Char) 、返された文字列の末尾を埋め込みます。 つまり、右から左の言語で使用すると、文字列の左側の部分が埋め込まれます。

注意

メソッドが PadRight 現在のインスタンスに空白文字を埋め込む場合、このメソッドは現在のインスタンスの値を変更しません。 代わりに、末尾 paddingChar の文字で埋め込まれた新しい文字列を返し、その長さの合計が totalWidth 文字になるようにします。

こちらもご覧ください

適用対象