C# String PadRight(Int32)
Description
String PadRight(Int32)
returns a new string that left-aligns
the characters in this string by padding them with spaces on the right, for
a specified total length.
Syntax
String.PadRight(Int32)
has the following syntax.
public string PadRight(
int totalWidth
)
Parameters
String.PadRight(Int32)
has the following parameters.
totalWidth
- The number of characters in the resulting string, equal to the number of original characters plus any additional padding characters.
Returns
String.PadRight(Int32)
method returns 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.
However, if totalWidth is less than the length of this instance, the method
returns a reference to the existing instance. If totalWidth is equal to the
length of this instance, the method returns a new string that is identical
to this instance.
Example
The following example demonstrates the PadRight method.
// w ww. ja va2 s . com
using System;
public class MainClass{
public static void Main(String[] argv){
string str = "java2s.com";
Console.Write("|");
Console.Write(str.PadRight(15));
Console.WriteLine("|");
}
}
The code above generates the following result.