Microsoft Doc says about String.Trim
Removes all leading and trailing white-space characters from the current String object.
But tabulator characters get removed too. Is tabulator defined as whitespace character?
If I don't want \t to be removed from Trim I guess I have to implement that myself, right?
The Tab character is considered whitespace, but you don't have to implement it yourself. Just use the overload that takes a list of characters to trim:
char[] charsToTrim = { '*', ' ', '\''};
string banner = "*** Much Ado About Nothing ***";
string result = banner.Trim(charsToTrim);
Tab is considered whitespace.
This contains a listing of what is considered whitespace in C#, under the Remarks header.
Trim alternatively allows you to set which characters you wish to strip, you may manually declare what you wish to trim, leaving the tab character out and not trimmed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With