Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why removes String.Trim Tabulator?

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?

like image 253
juergen d Avatar asked Oct 30 '25 17:10

juergen d


2 Answers

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);
like image 131
M.Babcock Avatar answered Nov 02 '25 07:11

M.Babcock


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.

like image 30
Chris Walsh Avatar answered Nov 02 '25 09:11

Chris Walsh