This documentation is archived and is not being maintained.

String.PadRight Method (Int32, Char)

.NET Framework 1.1

Left-aligns the characters in this string, padding on the right with a specified Unicode character, for a specified total length.

[Visual Basic]
Overloads Public Function PadRight( _
   ByVal totalWidth As Integer, _
   ByVal paddingChar As Char _
) As String
public string PadRight(
 int totalWidth,
 char paddingChar
public: String* PadRight(
 int totalWidth,
 __wchar_t paddingChar
public function PadRight(
   totalWidth : int,
 paddingChar : Char
) : String;


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

Return Value

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


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


Exception Type Condition
ArgumentException totalWidth is less than zero.


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

[Visual Basic] 
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|".

String *str = L"forty-two";
Console::Write(str->PadRight(15, L'.'));
Console::WriteLine(L"|"); // Displays "|forty-two......|".

Console::Write(str->PadRight(5, L'.'));
Console::WriteLine(L"|"); // Displays "|forty-two|".

var str : String = "forty-two";
var pad : char = ".";
Console.WriteLine(str.PadRight(15, pad)); // Displays "|forty-two......|".
Console.WriteLine(str.PadRight(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.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

String Class | String Members | System Namespace | String.PadRight Overload List | Char | Int32 | PadLeft | Trim