Open In App

JSTL fn:startsWith() Function

In JSTL the fn:startsWith() function is used to check if a given string starts with a particular prefix. This function returns the boolean value as True or False according to the check result.

In this article, we will see the detailed Syntax of the fn:startsWith() function along with its parameters, we will also see the practical implementation of this function in terms of examples.



Syntax of JSTL fn:startsWith() Function

${fn:startsWith(string, prefix)}

Where,

Example of JSTL fn:startsWith() Function

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






<%@ 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:startsWith() Example</title>
  </head>
  <body>
    <c:set var="inputString" value="GeeksforGeeks"/>
    <h3>Original String: ${inputString}</h3>
    <p>Starts with "Geeks": ${fn:startsWith(inputString, 'Geeks')}</p>
    <p>Starts with "Java": ${fn:startsWith(inputString, 'Java')}</p>
  </body>
</html>

Output:

Original String: GeeksforGeeks
Starts with "Geeks": true
Starts with "Java": false

Output Screen of the JSTL fn:startsWith() Function Program:

Explanation of the above Program:


Article Tags :