asp.net.ph

String.PadLeft Method ( Int32, Char )

System Namespace   String Class


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

[ VB ]
<Serializable>
Overloads Public Function PadLeft ( _
   ByVal totalWidth As Integer, _
   ByVal paddingChar As Char _
) As String

[ C# ]
[ Serializable ]
public string PadLeft (
   int totalWidth,
   char paddingChar
);

[ C++ ]
[ Serializable ]
public: String* PadLeft (
   int totalWidth,
   __wchar_t paddingChar
);

[ JScript ]
public Serializable
function PadLeft (
   totalWidth : int,
   paddingChar : Char
) : String;

Parameters

totalWidth
The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.
paddingChar
A Unicode padding character.

Return Value

A new String that is equivalent to this instance, but right-aligned and padded on the left with as many paddingChar characters as needed to create a length of totalWidth.

-or-If totalWidth is less than the length of this instance, a new String that is identical to this instance.

Exceptions


Exception Type Condition
ArgumentException totalWidth is less than zero.

Example

[ VB ]
Dim str As String
Dim bar As Char
str = "forty-two"
bar = "."c
Response.WriteLine ( str.PadLeft ( 15, bar ) ) ' Displays "......forty-two".
Response.WriteLine ( str.PadLeft ( 2,  bar ) ) ' 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 = ".";
Response.WriteLine ( str.PadLeft ( 15, pad ) ) // Displays "......forty-two".
Response.WriteLine ( str.PadLeft ( 2,  pad ) ) // Displays "forty-two".
See Also

String Members   String.PadLeft Overload List   Char   Int32   PadRight   Trim Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph