JSTL fn:substringAfter() Function

In the main string, if we want to return the subset of the string followed by a specific substring then we can use the JSTL fn:substringAfter() Function.

JSTL substringAfter() Function

This function mainly returns the portion of the string that comes after the given string value.

In this article, we will see the detailed Syntax of the fn:substringAfter() function along with its parameters, we will also see the practical implementation of this function in terms of examples.

Syntax of substringAfter() Function

${fn:substringAfter(String str, String delimiter)}


Where,

  • ${fn:substringAfter( . . . )}: This is the JSTL function used to return the subset of the string followed by a specific substring.
  • str: This is the main string or input string from which the subset of the string will be extracted.
  • delimiter: The delimiter or marker after which the subset of the string will be returned.

Example of JSTL fn:substringAfter() Function

Below is the implementation of JSTL fn:substringAfter() 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 substringAfter Example</title>
  </head>
  <body>
    <c:set var="string1" value="Welcome to w3wiki."/>
      
    <c:set var="substringResult" value="${fn:substringAfter(string1, 'Beginner')}" />
      
    <p>Original String: ${string1}</p>
    <p>Substring after "Beginner": ${substringResult}</p>
  </body>
</html>


Output:

Explanation of the above Program:

  • In the above example, firstly we have initialised values to the string1 and substringResult variable as “Welcome to w3wiki” and the function output.
  • We are using the fn:substringAfter() Function in which we have passed the parameter of string1 and the delimiter as “Beginner“.
  • So we have got the result as forBeginner which is substring after Beginner delimiter.
  • We have printed the result in HTML by using the <p> tag.

Contact Us