Tuesday, 8 September 2009

String.PadLeft() Total Length Clarification



Very quick note on String.PadLeft() to clear up some confusion. The specified total length is actually the minimum total length for the string.

E.g.

"5".PadLeft(2, Convert.ToChar("0"))
Output = 05

"55".PadLeft(2, Convert.ToChar("0"))
Output = 55

"555".PadLeft(2, Convert.ToChar("0"))
Output = 555

Microsoft documentation: http://msdn.microsoft.com/en-us/library/system.string.padleft.aspx

No comments: