Open In App

JSTL fn:containsIgnoreCase() Function

Last Updated : 08 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In the input string, if we need to check whether the input string has the specified string or not by ignoring its case then we can use the JSTL fn:containsIgnoreCase() Function. In this article, we will see the detailed Syntax of the fn:containsIgnoreCase() function along with its parameters, we will also see the practical implementation of this function in terms of examples.

JSTL fn:containsIgnoreCase() Function

This function returns the boolean value as true. If the input string has the specified string by ignoring the case otherwise, the false value is been returned.

Syntax of JSTL fn:containsIgnoreCase() Function

${fn:containsIgnoreCase(String str, String substring)}

Where,

  • ${fn:containsIgnoreCase( . . . )}: This is the JSTL expression to check whether the input string has the specified string by ignoring the case.
  • str: This is the input string in which the search of the specified string will be done.
  • substring: This is the specified string to check for within the input string.

Example of JSTL fn:containsIgnoreCase() Function

Below is the implementation of JSTL fn:containsIgnoreCase() Function:

HTML




<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ 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 fn:containsIgnoreCase() Example</title>
  </head>
  <body>
    <c:set var="mainString" value="Welcome to GeeksforGeeks"/>
    <c:set var="substring1" value="geeks"/>
    <c:set var="substring2" value="Java"/>
    <p>Original String: ${mainString}</p>
      
    <p>Does "${mainString}" contain "${substring1}" (case-insensitive)? ${fn:containsIgnoreCase(mainString, substring1)}</p>
    <p>Does "${mainString}" contain "${substring2}" (case-insensitive)? ${fn:containsIgnoreCase(mainString, substring2)}</p>
      
  </body>
</html>


Output:

Output of JSTL fn:containsIgnoreCase() Function Example

Explanation of the above Program:

  • In the above example, we have initialized the variables mainString, substring1, and substring2 with the values “Welcome to GeeksforGeeks“, “geeks“, and “java“.
  • Then by using the fn:containsIgnoreCase() function, we are checking if the original main string contains the specified substrings in a case-insensitive manner.
  • We have got the output for substring1 as true because the substring is present in the mainstring in a case-insensitive manner whereas for the substring2 the result is false as the substring2 is not present in the mainstring.
  • We are printing the output in HTML by using the <p> tag.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads