JSTL Functions – substring()

The fn:substring() function returns a subset of a string specified by start and end indices.


The fn:substring () function has following syntax:

java.lang.String substring(java.lang.String, int, int)

JSTL Example :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<title>JSTL Tutorial</title>

<c:set var="str1" value="www.c4learn.com"/>
<c:set var="str2" value="${fn:substring(string1, 4, 11)}" />

<p>Final sub string : ${str2}</p>


Output :

Final sub string : c4learn