Or, if you're not sure what's in the string, safer to say
str = (str == null) ? null : str.Trim();
As an aside, I very rarely use Trim() because almost invariably what I
want to do isn't simply trim a string, but do something more akin to
XPath's normalize_space() function: remove all leading and
http://msdn2.microsoft.com/en-us/library/t97s7bs3.aspx
Pretty straight forward:
String myString = " Testing Testing 123 ";
Console.WriteLine(myString.Trim());
This will produce "Testing Testing 123" (notice the lack of spaces before
and after the string contents). There is also TrimEnd() an
> Can anyone tell me how to use string function Trim in C#?
The thing to remember is that string are immutable in C#/ .Net, so
calling Trim against one doesn't change THAT string, it returns a NEW
string... you want this:
string foo = "Blah ";
foo = foo.Trim();
--
"Your lack of planning DOES c
Can anyone tell me how to use string function Trim in C#?
Sincerely,
Tracy Ding
XYPRO Technology
USA HQ phone: +1-805-583-2874
===
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.d