JSTL fn:substringBefore() Function
Last Updated :
17 Dec, 2023
In JSTL, the fn:substringBefore() function is mainly used to return the subset of the string before a specific substring. This function extracts the substring before a specified delimiter in the given input string. In this article, we will discuss about the syntax, parameters, and example of the fn:substringBefore() function.
- The fn:substringBefore() function is part of the JSTL core tag library.
- The function simplifies the string manipulation in JSP applications.
Syntax of fn:substringBefore() function:
${fn:substringBefore(string, delimiter)}
- ${fn:substringBefore(..)}: This is the JSTL expression for extracting a subset of a string.
- string: This is the input string parameter from which we need to extract the substring.
- delimiter: This is the delimiter attribute that defines the end of the substring to be extracted.
Example of JSTL fn:substringBefore() Function
In this example, we will see how to find the length of a string using the JSTL fn:substringBefore() Function.
HTML
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
< html >
< head >
< title >JSTL fn:substringBefore() Example</ title >
</ head >
< body >
< c:set var = "inputString" value = "GeeksforGeeks is Good" />
< p >Original String: ${inputString}</ p >
< p >Substring before "is": ${fn:substringBefore(inputString, 'is')}</ p >
</ body >
</ html >
|
Output:
Original String: GeeksforGeeks is Good
Substring before "is": GeeksforGeeks
Output Screen of the above Program:
Explanation of the above Program:
- We have initialized the inputString variable with the string value “GeeksforGeeks is Good”.
- Then, by using the fn:substringBefore() function, we extract the substring before the occurrence of the substring as “is“.
- So before the substring, the output is GeeksforGeeks which we are printing on screen by using the <p> tag of HTML.
Share your thoughts in the comments
Please Login to comment...