JSTL fn:startsWith() Function
Last Updated :
14 Dec, 2023
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.
- If the input string begins with the prefix then true is been returned else false is been returned.
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,
- ${fn:startsWith()}: This is the JSTL expression that is used to check whether the string starts with the specified prefix.
- string: This is the input string that will be checked.
- prefix: This is the value or character that we will check if it is at the beginning of the input string.
Example of JSTL fn:startsWith() Function
Below is the implementation of JSTL fn:startsWith() Function:
HTML
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
< 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:
- In the above example, we have initialized the variable inputString with the value GeeksforGeeks using the c:set
- Then, we check using the fn:startsWith() whether the prefix Geeks is present in the inputString. As we can see the prefix is present and starts in the inputString, so the function has returned the output as true. We have printed this output using a simple <p> tag in HTML.
- In the next condition, we are checking in inputString, whether the prefix Java starts at the beginning. We can easily notice that there is no Java prefix at the beginning of the inputString, so the function has returned the result as false. We have printed it using <p> tag.
Share your thoughts in the comments
Please Login to comment...