fn:substring() JSTL Function

fn:substring() JSTL Function Example explains about How To Use fn:substring() JSTL Function.

Consider an example where you need to find a substring.

fn:substring() JSTL function will returns a substring of a string that we specified. For this you need to specify the indexes for extracting the substring as below format

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

You can see the below example, which is demonstrating fn:trim() JSTL Function

Required Libraries

You need to download

  1. Tomcat 9
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

fn:substring() 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 fn:substring</title>
</head>
<body>

<%
    // you can also set the values into request scope same as using c:set
    // request.setAttribute("str", "This is a TEST String");
%>

    <c:set var="str" value="This is a TEST String" />
    ${fn:substring(str, 0,4)}

</body>
</html>
Output
is a TEST String

 









Your email address will not be published. Required fields are marked *