JSTL Functions – indexOf()

The fn:indexOf() function returns the index within a string of a specified substring.


The fn:indexOf() function has following syntax:

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

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="string1" value="Java is simple and easy"/>

<p>Index of 'is' : ${fn:indexOf(string1, "is")}</p>


This would produce following result:

Index of 'is' : 5