PadLeft and PadRight pad a string to a given length with a specified character or a space if unspecified.
using System; class MainClass//from w w w . ja v a 2s .co m { public static void Main(string[] args) { Console.WriteLine ("12345".PadLeft (9, '*')); Console.WriteLine ("12345".PadLeft (9)); } }
If the input string is longer than the padding length, the original string is returned unchanged.
using System; class MainClass/*from w w w . j av a 2 s. co m*/ { public static void Main(string[] args) { Console.WriteLine ("12345".PadLeft (2, '*')); Console.WriteLine ("12345".PadLeft (2)); } }