Why string.IsNullOrWhiteSpace(“\0”) is false

前端 未结 6 1810
不思量自难忘°
不思量自难忘° 2021-01-18 13:17

I faced a problem where invisible character \\0 which is pretty like a \'white space\' not considered as white space by the string.IsNullOrWhiteSpace method. I

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 13:42

    For fun historical reasons (they are surely fun, but I wasn't able to find them), null has two meanings... The null pointer/reference (called NULL in C), and the NUL (or NULL) \0 character.

    String.IsNullOrWhiteSpace does:

    Indicates whether a specified string is null, empty, or consists only of white-space characters.

    with null meaning the "null reference", empty meaning empty and white-space meaning

    White-space characters are defined by the Unicode standard. The IsNullOrWhiteSpace method interprets any character that returns a value of true when it is passed to the Char.IsWhiteSpace method as a white-space character.

    The list of characters that Char.IsWhiteSpace considers a space is present in the page of Char.IsWhiteSpace.

提交回复
热议问题