Open In App

JSTL fn:substringAfter() Function

Last Updated : 08 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 GeeksforGeeks."/>
      
    <c:set var="substringResult" value="${fn:substringAfter(string1, 'Geeks')}" />
      
    <p>Original String: ${string1}</p>
    <p>Substring after "Geeks": ${substringResult}</p>
  </body>
</html>


Output:

Output of the JSTL fn:substringAfter() Function

Explanation of the above Program:

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads