List Info

Thread: Trim function in c#




Trim function in c#
country flaguser name
United States
2008-04-10 18:14:13
 
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.develop.com


Re: Trim function in c#
user name
2008-04-10 18:56:30
> 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 constitute an emergency on
my part... so
PLAN BETTER! "

Marc C. Brooks
http://musingmarc.blog
spot.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


Re: Trim function in c#
user name
2008-04-10 19:02:03
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() and
TrimStart().
Also don't forget that strings are immutable in C# so
everytime you call
Trim() on a string you will get a new one back and the
original will be
unmodified.

-Pete

On Thu, Apr 10, 2008 at 7:14 PM, Tracy Ding <tracy_dxypro.com> wrote:

>
> 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(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )