简体   繁体   中英

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?

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.

Yes, tab is considered white-space. However, Trim has an overload that takes char[] and remove those characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM