Trim() question

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
 
O

Oleg Subachev

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

Oleg Subachev
 
B

Bobbo

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.
 
H

Hans Kesting

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top