簡體   English   中英

JSP中的空白

[英]white space in JSP

我想知道如何檢查JSP字符串中是否有空格。

例如:

字符串名稱=“ Richard hailes”;

我想知道上面的字符串中是否有空格。

<c:if test="${fn:contains(name, ' ')}">
  It contains a space
</c:if>

有關JSTL的信息,請參見https://stackoverflow.com/tags/jstl/info

使用indexOf函數。

if(name.indexOf(' ') >= 0){
   // name have space
}

參見indexOf

public static boolean isBlank(String str){int strLen; if(str == null ||(strLen = str.length())== 0){返回true;} for(int i = 0; i <strLen; i ++){if(((Character.isWhitespace(str.charAt (i))==假)){返回假;}}返回真;}}

使用正則表達式。 看到這個例子;

    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");
     }

您可以查看此頁面該頁面描述了如何在JSP中使用contains函數。 您可以使用它來查看字符串是否包含“”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM