String.PadLeft 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 문자열의 시작 부분에 공백이나 지정된 유니코드 문자가 채워지는 지정된 길이의 새 문자열을 반환합니다.
오버로드
| Name | Description |
|---|---|
| PadLeft(Int32) |
지정된 총 길이에 대해 왼쪽에 공백으로 패딩하여 이 인스턴스의 문자를 오른쪽에 맞추는 새 문자열을 반환합니다. |
| PadLeft(Int32, Char) |
지정된 총 길이에 대해 지정된 유니코드 문자로 왼쪽에 패딩하여 이 인스턴스의 문자를 오른쪽에 맞추는 새 문자열을 반환합니다. |
PadLeft(Int32)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 총 길이에 대해 왼쪽에 공백으로 패딩하여 이 인스턴스의 문자를 오른쪽에 맞추는 새 문자열을 반환합니다.
public:
System::String ^ PadLeft(int totalWidth);
public string PadLeft(int totalWidth);
member this.PadLeft : int -> string
Public Function PadLeft (totalWidth As Integer) As String
매개 변수
- totalWidth
- Int32
결과 문자열의 문자 수(원래 문자 수와 추가 패딩 문자 수)입니다.
반품
이 인스턴스와 동일하지만 길이를 만드는 totalWidth데 필요한 만큼의 공백으로 왼쪽에 오른쪽 맞춤 및 패딩된 새 문자열입니다. 그러나 이 인스턴스의 길이보다 작은 경우 totalWidth 메서드는 기존 인스턴스에 대한 참조를 반환합니다. 이 인스턴스의 길이와 같으면 totalWidth 메서드는 이 인스턴스와 동일한 새 문자열을 반환합니다.
예외
totalWidth가 0보다 작습니다.
예제
다음 예제에서는 메서드를 보여 줍니다 PadLeft .
string str = "BBQ and Slaw";
Console.WriteLine(str.PadLeft(15)); // Displays " BBQ and Slaw".
Console.WriteLine(str.PadLeft(5)); // Displays "BBQ and Slaw".
let str = "BBQ and Slaw"
printfn $"{str.PadLeft 15}" // Displays " BBQ and Slaw".
printfn $"{str.PadLeft 5}" // Displays "BBQ and Slaw".
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".
설명
유니코드 공간은 16진수 0x0020 정의됩니다.
메서드는 PadLeft(Int32) 반환된 문자열의 시작을 채깁니다. 즉, 오른쪽에서 왼쪽 언어로 사용할 경우 문자열의 오른쪽 부분을 채워 줍니다.
메모
메서드가 PadLeft 현재 인스턴스를 공백 문자로 채우면 이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 총 길이가 문자가 되도록 선행 공백으로 채워지는 새 문자열을 반환합니다 totalWidth .
추가 정보
적용 대상
PadLeft(Int32, Char)
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
- Source:
- String.Manipulation.cs
지정된 총 길이에 대해 지정된 유니코드 문자로 왼쪽에 패딩하여 이 인스턴스의 문자를 오른쪽에 맞추는 새 문자열을 반환합니다.
public:
System::String ^ PadLeft(int totalWidth, char paddingChar);
public string PadLeft(int totalWidth, char paddingChar);
member this.PadLeft : int * char -> string
Public Function PadLeft (totalWidth As Integer, paddingChar As Char) As String
매개 변수
- totalWidth
- Int32
결과 문자열의 문자 수(원래 문자 수와 추가 패딩 문자 수)입니다.
- paddingChar
- Char
유니코드 패딩 문자입니다.
반품
이 인스턴스와 동일하지만 길이를 만드는 paddingChar데 필요한 만큼의 totalWidth 문자로 왼쪽에 오른쪽 맞춤 및 패딩된 새 문자열입니다. 그러나 이 인스턴스의 길이보다 작은 경우 totalWidth 메서드는 기존 인스턴스에 대한 참조를 반환합니다. 이 인스턴스의 길이와 같으면 totalWidth 메서드는 이 인스턴스와 동일한 새 문자열을 반환합니다.
예외
totalWidth가 0보다 작습니다.
예제
다음 예제에서는 메서드를 보여 줍니다 PadLeft .
using System;
class Sample
{
public static void Main()
{
string str = "forty-two";
char pad = '.';
Console.WriteLine(str.PadLeft(15, pad));
Console.WriteLine(str.PadLeft(2, pad));
}
}
// The example displays the following output:
// ......forty-two
// forty-two
let str = "forty-two"
let pad = '.'
printfn $"{str.PadLeft(15, pad)}"
printfn $"{str.PadLeft(2, pad)}"
// The example displays the following output:
// ......forty-two
// forty-two
Public Class Example
Public Shared Sub Main()
Dim str As String
Dim pad As Char
str = "forty-two"
pad = "."c
Console.WriteLine(str.PadLeft(15, pad))
Console.WriteLine(str.PadLeft(2, pad))
End Sub
End Class
' The example displays the following output:
' ......forty-two
' forty-two
설명
메서드는 PadLeft(Int32, Char) 반환된 문자열의 시작을 채깁니다. 즉, 오른쪽에서 왼쪽 언어로 사용할 경우 문자열의 오른쪽 부분을 채워 줍니다.
메모
메서드가 PadLeft 현재 인스턴스를 공백 문자로 채우면 이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 총 길이가 문자가 되도록 선행 paddingChar 문자로 채워지는 새 문자열을 반환합니다 totalWidth .