Alexey Romanov
Alexey Romanov

Reputation: 170733

Is this a bug in string.TrimEnd?

"\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.

Upvotes: 3

Views: 1086

Answers (3)

TcKs
TcKs

Reputation: 26632

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.

Upvotes: 3

Kobi
Kobi

Reputation: 138017

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.

Upvotes: 10

Dirk Vollmar
Dirk Vollmar

Reputation: 176169

What behavior would you expect?

If you want to remove trailing NULL characters you should use

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

Upvotes: 0

Related Questions