Is this a bug in string.TrimEnd?

"\u4000\f".TrimEnd(new char[0])

equal to "\u4000".

I am passing an empty array, so as per the MSDN documentation, nothing needs to be deleted and "\u4000\f"should be returned. Is there a reason for this behavior?

EDIT: Refined Expected Behavior

EDIT: Apparently this changed in 3.5, I looked at the 2.0 documentation page.

+3
source share
3 answers

the documentation says: "If trimChars is null (Nothing in Visual Basic) or an empty array, space characters are removed instead."
So no, not a mistake.

+10
source

The documentation is clear:

, String.

: System..::. String , - trimChars String. trimChars null (Nothing in Visual Basic) , .

, .

+3

What behavior do you expect?

If you want to remove trailing NULL characters, you should use

"\u4000\f".TrimEnd(new char[1])
0
source

All Articles