This post helps you understand how to use the <fn:substringAfter> tag in the JSTL function tags library with code example.

The fn:substringAfter function returns a string after the specified substring.

 

JSTL <fn:substringAfter> Syntax:

${fn:substringAfter(<string>, <substring>)}

 

JSTL <fn:substringAfter> Example:

The following JSP example outputs a string after the substring www.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>fn:substringAfter Demo</title>
  </head>
  <body>
    <h1>fn:substringAfter Demo</h1>
    <c:set var="text" value="www.CodeJava.net is great source of information."/>
    <c:set var="website" value="${fn:substringAfter(text,'www.')}" />
    Full Text: <strong><c:out value="${text}"/></strong><br/><br/>
    Text After Substring www. <strong><c:out value="${website}"/></strong><br/><br/>	
  </body>
</html>

 

Output:

JSTL function fn-substringAfter

 

Other JSTL Function Tags:

contains  |  containsIgnoreCase  |  endsWith |  escapeXml  |  indexOf  |  join  |  length  |  replace  |  split  |  startsWith  |  substring  |  substringBefore  |  toLowercase  |  toUpperCase  |  trim


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment