The JSTL fn:subString() function returns a sub string of the input string from the start index to the last index-1.
Syntax:
String subString(String inputString, int startIndex, int lastIndex)
Example:
test.jsp
<%@ 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>fn:substring JSTL function example</title> </head> <body> <c:set var="testString" value="Hello this is a JSTL function example."/> Given String: <br/> <c:out value="${testString}" /><br/><br/> Substring of the given string:<br/> <c:out value="${fn:substring(testString, 6, '29')}" /> </body> </html> |
web.xml
<web-app> <welcome-file-list> <welcome-file>test.jsp</welcome-file> </welcome-file-list> </web-app> |
Output:
Download this example.
Next Topic: JSTL fn:subStringAfter() function with example.
Previous Topic: JSTL fn:replace() function with example.