Latest web development tutorials

JSTL fn:containsIgnoreCase()函數

JSP 標準標籤庫 JSP標準標籤庫

fn:containsIgnoreCase()函數用於確定一個字符串是否包含指定的子串,忽略大小寫。

語法

fn:containsIgnoreCase()函數的語法如下:

<c:if test="${fn:containsIgnoreCase(<原始字符串>, <要查找的子字符串>)}">
...
</c:if>

實例演示

以下實例演示了這個函數的功能:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>使用 JSTL 函数</title>
</head>
<body>

<c:set var="theString" value="I am from w3big"/>

<c:if test="${fn:containsIgnoreCase(theString, 'w3big')}">
   <p>找到 w3big<p>
</c:if>

<c:if test="${fn:containsIgnoreCase(theString, 'w3big')}">
     <p>找到 w3big<p>
</c:if>

</body>
</html>

運行結果如下:

找到 w3big

找到 w3big

JSP 標準標籤庫 JSP標準標籤庫