Open In App

JSTL fn:substringBefore() Function

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.

Syntax of fn:substringBefore() function:

${fn:substringBefore(string, delimiter)}

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.




<%@ 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: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:

Article Tags :