JSTL Function fn:containsIgnoreCase Example
- Details
- Written by Nam Ha Minh
- Last Updated on 31 August 2019   |   Print Email
This post helps you understand how to use the <fn:containsIgnoreCase> tag in the JSTL function tags library with code example.
In JSTL, the fn:containsIgnoreCase function tests whether a given string is contained in another string by ignoring any upper case or lower case differences. This function returns boolean value.
JSTL <fn:containsIgnoreCase> Syntax:
<c:if test="${fn:containsIgnoreCase(<var containing source string>, <string to search>)}">
...
</c:if>
JSTL <fn:containsIgnoreCase> Example:
The following JSP code searches for "Code Java" in a given string value.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>fn:containsIgnoreCase Demo</title> </head> <body> <h1>fn:containsIgnoreCase Demo</h1> <c:set var="stringToSearch" value="CodeJava.net is a great source of information." /> <c:out value="${stringToSearch}"/> <c:if test="${fn:containsIgnoreCase(stringToSearch, 'codejava')}"> <p>The above sentence contains codejava</p> </c:if> </body> </html>
Output:
Other JSTL Function Tags:
contains | endsWith | escapeXml | indexOf | join | length | replace | split | startsWith | substring | substringAfter | substringBefore | toLowercase | toUpperCase | trim
Comments