JSTL Functions – indexOf()



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

Syntax:

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

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

<c:set var="string1" value="Java is simple and easy"/>

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

</body>
</html>

This would produce following result:

Index of 'is' : 5