如何在 JSP 中檢查一個輸入的字串忽略大小寫地包含某個指定的子字串?
fn:containsIgnoreCase() 函式用於確定輸入字串中是否包含指定的子字串。執行搜尋時忽略大小寫。
語法
fn:containsIgnoreCase() 函式具有以下語法 -
boolean containsIgnoreCase(java.lang.String, java.lang.String)
示例
以下示例將說明 fn:containsIgnoreCase() 函式的功能 -
<%@ 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>Using JSTL Functions</title>
</head>
<body>
<c:set var = "theString" value = "I am a test String"/>
<c:if test = "${fn:containsIgnoreCase(theString, 'test')}">
<p>Found test string<p>
</c:if>
<c:if test = "${fn:containsIgnoreCase(theString, 'TEST')}">
<p>Found TEST string<p>
</c:if>
</body>
</html>你將收到以下結果 -
Found test string Found TEST string
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP