Horje
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.

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

Output of Example of JSTL fn:substringBefore() Function

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.



Reffered: https://www.geeksforgeeks.org


Geeks Premier League

Related
PHP Program to Find Square Root of a Number PHP Program to Find Square Root of a Number
PHP Program to Merge two Sorted Arrays PHP Program to Merge two Sorted Arrays
PHP Program to Find LCM of Two Numbers PHP Program to Find LCM of Two Numbers
Hexadecimal to Decimal Conversion in PHP Hexadecimal to Decimal Conversion in PHP
PHP Program to Add Two Binary Numbers PHP Program to Add Two Binary Numbers

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14