34,333
edits
Changes
no edit summary
== Trimming and Padding C# Strings ==
Unwanted leading and trailing spaces can be removed from a string using the ''Trim()'' method. When called, this method returns a modified version of the stringwith both leading and trailing spaces removed:
<pre>
[hello]
</pre>
The remove just the leading or trailing spaces use the ''TrimStart()'' or ''TrimEnd()'' method respectively.
In inverse of the ''Trim()'' method are the ''PadLeft()'' and ''PadRight()'' methods. These methods allow leading or trailing characters to be added to a string. The methods take as arguments the total number of characters to which the string is to be padded and the padding character: