views:

603

answers:

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

is equal to "\u4000".

I am passing an empty array, so according to the MSDN documentation nothing should be removed and "\u4000\f" should be returned. Is there a reason for this behaviour?

EDIT: Clarified expected behaviour

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

+3  A: 

The documentation is clear:

Removes all trailing occurrences of a set of characters specified in an array from the current String object.

Return Value Type: System..::.String The string that remains after all occurrences of the characters in the trimChars parameter are removed from the end of the current String object. If trimChars is null (Nothing in Visual Basic) or an empty array, white-space characters are removed instead.

So your example is not bug.

TcKs
The array is empty. So nothing should be removed.
Alexey Romanov
A: 

What behavior would you expect?

If you want to remove trailing NULL characters you should use

"\u4000\f".TrimEnd(new char[1])
0xA3
+10  A: 

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

Kobi