Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.PadLeft Method

Right-aligns the characters in this instance, padding on the left with spaces or a specified Unicode character for a specified total length.

Overload List

Right-aligns the characters in this instance, padding with spaces on the left for a specified total length.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function PadLeft(Integer) As String
[C#] public string PadLeft(int);
[C++] public: String* PadLeft(int);
[JScript] public function PadLeft(int) : String;

Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function PadLeft(Integer, Char) As String
[C#] public string PadLeft(int, char);
[C++] public: String* PadLeft(int, __wchar_t);
[JScript] public function PadLeft(int, Char) : String;

Example

[Visual Basic, C++, JScript] The following code example demonstrates the PadLeft method.

[Visual Basic, C++, JScript] Note   This example shows how to use one of the overloaded versions of PadLeft. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim str As String
Dim pad As Char
str = "forty-two"
pad = "."c
Console.WriteLine(str.PadLeft(15, pad)) ' Displays "......forty-two".
Console.WriteLine(str.PadLeft(2,  pad)) ' Displays "forty-two".

[C++] 
String *str = L"forty-two";
Console::WriteLine(str-> PadLeft(15, L'.')); // Displays "......forty-two".
Console::WriteLine(str-> PadLeft(2,  L'.')); // Displays "forty-two".

[JScript] 
var str : String;
var pad : char;
str = "forty-two";
pad = ".";
Console.WriteLine(str.PadLeft(15, pad)) // Displays "......forty-two".
Console.WriteLine(str.PadLeft(2,  pad)) // Displays "forty-two".

[C#] No example is available for C#. To view a Visual Basic, C++, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

String Class | String Members | System Namespace

Show:
© 2015 Microsoft