JSTL Function fn:substring Example
- Details
- Written by Nam Ha Minh
- Last Updated on 30 August 2019   |   Print Email
This post helps you understand how to use the <fn:substring> tag in the JSTL function tags library with code example.
The fn:substring function returns a substring from a string provided begin and end index.
JSTL <fn:substring> Syntax:
${fn:substring(<string>, <beginIndex>, <endIndex>)}
JSTL <fn:substring> Example:
The following JSP code extracts a substring from a string based on begin and end index values.
<%@ 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:substring Demo</title> </head> <body> <h1>fn:substring Demo</h1> <c:set var="text" value="CodeJava.net is great source of information."/> <c:set var="website" value="${fn:substring(text, 0, 12)}" /> Full Text: <strong><c:out value="${text}"/></strong><br/><br/> Substring Text (start index 0 - end index 12): <strong><c:out value="${website}"/></strong><br/><br/> </body> </html>
Output:
Other JSTL Function Tags:
contains | containsIgnoreCase | endsWith | escapeXml | indexOf | join | length | replace | split | startsWith | substringAfter | substringBefore | toLowercase | toUpperCase | trim
Comments
hiiii