Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0240 Padding string

Padding string is to add specified character to a string to a given length. We can choose the pad left or right. using System; class Sample { public static void Main() { string s = "rntsoft.com"; s = s.PadLeft(20,'='); Console.WriteLine(s); s = s.PadRight(40,'+'); Console.WriteLine(s); } } The output: ==========rntsoft.com ==========rntsoft.com++++++++++++++++++++