Trim() question

  • Thread starter Thread starter Oleg Subachev
  • Start date Start date
O

Oleg Subachev

If I apply Trim() method to string consisting of two x0D and x0A characters
the resulting string is not empty but contain the same two charaters: x0D,
x0A.

But according to the help Trim() method
"removes all occurrences of white space characters from the beginning and
end".
And CARRIAGE RETURN (U+000D) and LINE FEED (U+000A) are among
white space characters removed by the Trim() method.

What's wrong ?

Oleg Subachev
 
Trim( new char[] { (char) 0x0A, (char) 0x0D } ) doesn't help also.

Oleg Subachev
 
If I apply Trim() method to string consisting of two x0D and x0A characters
the resulting string is not empty but contain the same two charaters: x0D,
x0A.

Hmmm,

Unless I'm doing something wrong, this seems to work as expected for
me:

string s = new string(new char[] {(char)0x0a,
(char)0x0d });
Console.WriteLine(s.Length);
Console.WriteLine(s.Trim().Length);

i.e. The first length call yields 2, the second 0.
 
If I apply Trim() method to string consisting of two x0D and x0A
characters the resulting string is not empty but contain the same two
charaters: x0D, x0A.

But according to the help Trim() method
"removes all occurrences of white space characters from the beginning
and
end".
And CARRIAGE RETURN (U+000D) and LINE FEED (U+000A) are among
white space characters removed by the Trim() method.
What's wrong ?

Oleg Subachev

How do you "apply that Trim() method"?

If it is something like:
String s = ...
s.Trim();

then it will not work. Trim is a function that returns a new, trimmed string
instead of
trimming the instance it is called on. So:
String s = ...
s = s.Trim();


Hans Kestin
 
Back
Top