String.Trim()
returns a string which equals the input string with all white-spaces trimmed from start and end:
" A String ".Trim() -> "A String"
String.TrimStart()
returns a string with white-spaces trimmed from the start:
" A String ".TrimStart() -> "A String "
String.TrimEnd()
returns a string with white-spaces trimmed from the end:
" A String ".TrimEnd() -> " A String"
None of the methods modify the original string object.
(In some implementations at least, if there are no white-spaces to be trimmed, you get back the same string object you started with:
csharp> string a = "a";
csharp> string trimmed = a.Trim();
csharp> (object) a == (object) trimmed;
returns true
I don't know whether this is guaranteed by the language.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…