如何检查字符串是否包含空格以外的内容?
此代码不起作用:
String string = " \n\n\t\t ";
if(string.length()==0) doSomething();
因为空格和换行都有值。
谁能告诉我该怎么做?
注意事项:minSDKVersion = 5
问候 :)
尝试这个:
if (string.trim().length() == 0) { /* all white space */ }
另外,您可以使用正则表达式:
if (string.matches("\\w*")) { . . . }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句