Search This Blog

Friday, March 29, 2013

PadLeft and PadRight C#

C# > StringPadRight & PadLeft

PadRight left aligns the characters in this string, padding on the right with a specified Unicode character.
PadLeft right aligns the characters in this string, padding on the lefy with a specified Unicode character.

Example:

string str = "four";
char pad = '.';
string str2 = str.PadLeft(7, pad); // "...four"
string str3 = str.PadRight(7, pad); //"four..."