String.PadLeft 메서드

정의

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

오버로드

PadLeft(Int32)

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

PadLeft(Int32, Char)

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

PadLeft(Int32)

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

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

결과 문자열에 있는 문자 수는 원래 문자 수와 추가 안쪽 여백 문자 수를 합한 값과 같습니다.

반환

String

이 인스턴스와 동일하지만 오른쪽으로 맞춰지고 왼쪽의 안쪽 여백이 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".
string str = "BBQ and Slaw";
Console.WriteLine(str.PadLeft(15));  // Displays "   BBQ and Slaw".
Console.WriteLine(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)

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

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

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

반환

String

이 인스턴스와 동일하지만 오른쪽으로 맞춰지고 왼쪽의 안쪽 여백이 paddingChar의 길이만큼 totalWidth 문자로 채워진 새 문자열입니다. 그러나 totalWidth가 이 인스턴스의 길이보다 작을 경우 메서드는 기존 인스턴스에 대한 참조를 반환합니다. totalWidth가 이 인스턴스의 길이와 같을 경우 메서드는 이 인스턴스와 동일한 새 문자열을 반환합니다.

예외

totalWidth가 0보다 작은 경우

예제

다음 예제는 PadLeft 메서드.

using namespace System;

void main()
{
   String^ str = "forty-two";
   Console::WriteLine( str->PadLeft( 15, L'.' ) ); 
   Console::WriteLine( str->PadLeft( 2, L'.' ) ); 
}
// The example displays the following output:
//       ......forty-two
//       forty-two
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
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 반환합니다.

추가 정보

적용 대상