Check if a single character is a whitespace?

后端 未结 9 1198
清酒与你
清酒与你 2021-02-06 21:21

What is the best way to check if a single character is a whitespace?

I know how to check this through a regex.

But I am not sure if this is the best way if I onl

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 22:08

    this covers spaces, tabs and newlines:

    if ((ch == ' ') || (ch == '\t') || (ch == '\n'))
    

    this should be best for performance. put the whitespace character you expect to be most likely, first.

    if performance is really important, probably best to consider the bigger picture than individual operations like this...

提交回复
热议问题