Export (0) Print
Expand All

String.PadRight Method (Int32)

.NET Framework 1.1

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

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

Parameters

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

Return Value

A new String that is equivalent to this instance, but left-aligned and padded on the right with as many spaces 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.

Remarks

A Unicode space is defined as hexadecimal 0x20.

Example

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

[Visual Basic] 
[C++] 
String *str = L"BBQ and Slaw";
Console::Write(L"|");
Console::Write(str->PadRight(15));
Console::WriteLine(L"|"); // Displays "|BBQ and Slaw   |".

Console::Write(L"|");
Console::Write(str->PadRight(5));
Console::WriteLine(L"|"); // Displays "|BBQ and Slaw|".

[JScript] 
var str : String;
str = "BBQ and Slaw";
Console.Write("|");
Console.Write(str.PadRight(15));
Console.WriteLine("|"); // Displays "|BBQ and Slaw   |".

Console.Write("|");
Console.Write(str.PadRight(5));
Console.WriteLine("|"); // Displays "|BBQ and Slaw|".

[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.

Requirements

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 | Int32 | PadLeft | Trim

Show:
© 2014 Microsoft