JSTL Functions – substring()



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

Syntax:

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" %>

<html>
<head>
<title>JSTL Tutorial</title>
</head>
<body>

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

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

</body>
</html>

Output :

Final sub string : c4learn