String.PadRight メソッド

定義

現在の文字列の末尾にスペースまたは指定した Unicode 文字を埋め込む、指定した長さの新しい文字列を返します。

オーバーロード

名前 説明
PadRight(Int32)

指定した合計長の右側にスペースを埋め込むことで、この文字列内の文字を左揃えにする新しい文字列を返します。

PadRight(Int32, Char)

指定した長さの Unicode 文字を右に埋め込むことで、この文字列内の文字を左揃えにする新しい文字列を返します。

PadRight(Int32)

ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
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;
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) メソッドは、返された文字列の末尾を埋め込みます。 つまり、右から左の言語で使用すると、文字列の左側の部分が埋め込まれます。

Note

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

こちらもご覧ください

適用対象

PadRight(Int32, Char)

ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
String.Manipulation.cs
ソース:
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 埋め込み文字。

返品

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

例外

totalWidth が 0 未満です。

次の例では、 PadRight メソッドを示します。

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) メソッドは、返された文字列の末尾を埋め込みます。 つまり、右から左の言語で使用すると、文字列の左側の部分が埋め込まれます。

Note

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

こちらもご覧ください

適用対象