简体   繁体   中英

Stop C# string.Trim() removing FF character?

Is there any way of stopping string.Trim() from removing an FF character?

I am parsing a file wanrt to be able to tell the difference between an empty line with just an FF char, a line of spaces with an FF char, and a line of "data" with an FF char.

However, if I test string.Trim() == string.Empty then it returns true for all of:

"\f"
"                               "
"                             \f"

eg It is also trimming the \\f out of the string?

Note: I can test for the \\f using Regex, but interested in why the trim removes the \\f as well?

From the MSDN:

string.trim

White-space characters are defined by the Unicode standard. The Trim() method removes any leading and trailing characters that produce a return value of true when they are passed to the Char.IsWhiteSpace method.

http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx

From Char.IsWhiteSpace

White space characters are the following Unicode characters: The characters CHARACTER TABULATION (U+0009), LINE FEED (U+000A), LINE TABULATION (U+000B), FORM FEED (U+000C), CARRIAGE RETURN (U+000D), NEXT LINE (U+0085), and NO-BREAK SPACE (U+00A0).

http://msdn.microsoft.com/en-us/library/t809ektx.aspx

That's why it's getting stripped out.

Hope this helps

Because it is designed to remove it. See MSDN

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