fn:substringBefore() JSTL Function

fn:substringBefore() JSTL Function Example explains about how to returns a subset of a string before a particular substring.

Consder an example where you need to find a part of a string before a specified substring.

fn:substringBefore() function returns a part of a particular string before a particular substring.

java.lang.String  substringBefore ( java.lang.String,  java.lang.String )

You can see the below example, which is demonstrating fn:substringBefore() JSTL Function

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:substringBefore() Example

<%@ 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</title>
</head>
<body>

    <%
    // you can also set the values into request scope same as using c:set
    // request.setAttribute("str", "This is a Test String");
    %>

    <c:set var="str" value="This is a TEST String" />
    ${fn:substringBefore(str, 'a')}

</body>
</html>
Output
This is

 









Your email address will not be published. Required fields are marked *