Open In App

JSTL fn:endsWith() Function

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

In the given string, if we need to check that the string ends with the specified suffix then we can use the JSTL fn:endsWith() Function. This function mainly returns the result in Boolean form. In this article, we will discuss about the syntax, parameters, and example of the fn:endsWith() function.

  • If the string ends with the specified suffix, then the result should return true else the false.
  • The fn:endsWith() function is part of the JSTL core tag library.

Syntax of fn:endsWith() function:

${fn:endsWith(String str, String suffix)}

Where,

  • ${fn:endsWith(. . .)}: This is the JSTL expression for checking if the string ends with the specified suffix.
  • str: This is the input string.
  • suffix: This is the suffix value we need to check at the end of the input string.

Example of JSTL fn:endsWith() Function

In this example, we will see how to find the length of a string using the JSTL fn:endsWith() 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:endsWith() Example</title>
</head>
<body>
<c:set var="inputString" value="GeeksforGeeks"/>
<c:set var="trueSuffix" value="Geeks"/>
<c:set var="falseSuffix" value="Java"/>
<p>Original String: ${inputString}</p>
<p>Does "${inputString}" end with "${trueSuffix}"? ${fn:endsWith(inputString, trueSuffix)}</p>
<p>Does "${inputString}" end with "${falseSuffix}"? ${fn:endsWith(inputString, falseSuffix)}</p>
  
</body>
</html>


Output:

Original String: GeeksforGeeks
Does "GeeksforGeeks" end with "Geeks"? true
Does "GeeksforGeeks" end with "Java"? false

Output Screen of the above Program:

Output Example of JSTL fn:endsWith() Function

Explanation of the above Program:

  • In the above example, firstly we have defined the value of input String as “GeeksforGeeks“. Along with this we have also defined the suffix values in the trueSuffix (Geeks) and falseSuffix (Java).
  • Then by using the JSTL fn:endsWith() Function, we are checking whether the inputString ends with trueSuffix or falseSuffix values.
  • In the output, we can see that the result for trueSuffix (Geeks) is true because, in the inputString, the sting ends with Geeks word whereas the falseSuffix (Java) gave the false result because in the inputString, there is no Java at the end.
  • We are printing the results using <p> tag of HTML.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads