java 性格比较
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7640278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Character Comparison
提问by Vernah
I'm currently doing an online course, however it doesn't seem to enjoy this method: Character.isWhiteSpace(c)
我目前正在做一个在线课程,但它似乎并不喜欢这种方法: Character.isWhiteSpace(c)
What other methods are there that can answer the below question?
还有哪些方法可以回答以下问题?
Assume that c
is a char variable has been declared and already given a value. Write an expression whose value is true if and only if x
is what is called a whitespace character (that is a space or a tab or a newline-- none of which result in ink being printed on paper).
假设c
已经声明了一个 char 变量并且已经给定了一个值。编写一个表达式,其值为真当且仅当x
是所谓的空白字符(即空格、制表符或换行符——它们都不会导致墨水打印在纸上)。
回答by Jon Newmuis
回答by Bohemian
There is a java API for this: Character.isWhiteSpace(c)
有一个Java API: Character.isWhiteSpace(c)
回答by ratchet freak
if you don't want to/can't use libraries
如果您不想/不能使用库
c==' '||c=='\t'||c=='\n'||c=='\r'
note that \r
is a carriage return it's part of the windows \r\n
combination (and used commonly in network protocols)
请注意,这\r
是一个回车,它是 windows\r\n
组合的一部分(并且通常用于网络协议)