String.PadRight 메서드

정의

현재 문자열의 끝 부분이 공백이나 지정된 유니코드 문자로 채워지는 지정된 길이의 새 문자열을 반환합니다.

오버로드

PadRight(Int32)

지정한 길이만큼 오른쪽의 안쪽 여백을 공백으로 채워서 이 문자열의 문자를 왼쪽에 맞추는 새 문자열을 반환합니다.

PadRight(Int32, Char)

지정한 길이만큼 오른쪽의 안쪽 여백을 지정된 유니코드 문자로 채워서 이 문자열의 문자를 왼쪽에 맞추는 새 문자열을 반환합니다.

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|".

설명

유니코드 공간은 16진수 0x0020 정의됩니다.

메서드는 PadRight(Int32) 반환된 문자열의 끝을 패딩합니다. 즉, 오른쪽에서 왼쪽 언어와 함께 사용하면 문자열의 왼쪽 부분이 채워지게 됩니다.

참고

메서드가 PadRight 현재 인스턴스를 공백 문자로 채우면 이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 총 길이 totalWidth 가 문자가 되도록 후행 공백으로 채워지는 새 문자열을 반환합니다.

추가 정보

적용 대상

PadRight(Int32, Char)

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

지정한 길이만큼 오른쪽의 안쪽 여백을 지정된 유니코드 문자로 채워서 이 문자열의 문자를 왼쪽에 맞추는 새 문자열을 반환합니다.

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

유니코드 안쪽 여백 문자입니다.

반환

이 인스턴스와 동일하지만 왼쪽으로 맞춰지고 오른쪽의 안쪽 여백이 paddingChar의 길이만큼 totalWidth 문자로 채워진 새 문자열입니다. 그러나 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 현재 인스턴스를 공백 문자로 채우면 이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 총 길이 totalWidth 가 문자가 되도록 후행 paddingChar 문자로 채워지는 새 문자열을 반환합니다.

추가 정보

적용 대상