[英]white space in JSP
I want to know how to check if there is white space in a string or not in JSP. 我想知道如何检查JSP字符串中是否有空格。
EX : 例如:
String name = "Richard hailes"; 字符串名称=“ Richard hailes”;
I want to know if there is a space in above string or not. 我想知道上面的字符串中是否有空格。
<c:if test="${fn:contains(name, ' ')}">
It contains a space
</c:if>
See https://stackoverflow.com/tags/jstl/info for info about the JSTL. 有关JSTL的信息,请参见https://stackoverflow.com/tags/jstl/info 。
public static boolean isBlank(String str) { int strLen; public static boolean isBlank(String str){int strLen; if (str == null || (strLen = str.length()) == 0) { return true;} for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) {return false;}}return true;} }
if(str == null ||(strLen = str.length())== 0){返回true;} for(int i = 0; i <strLen; i ++){if(((Character.isWhitespace(str.charAt (i))==假)){返回假;}}返回真;}}
Use regular expression. 使用正则表达式。 See this sample;
看到这个例子;
String patternStr = "\\s+";
String inputStr = "Richard hailes";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(inputStr);
if(matcher.find()) {
System.out.println("Found");
} else {
System.out.println("Not Found");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.