JSTL – substringBefore()



The fn:substringBefore() function returns the part of a string before a specified substring.

Syntax:

The fn:substringBefore() function has following syntax:

java.lang.String substringBefore(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="str1" value="www.c4learn.com"/>
<c:set var="str2" value="${fn:substringBefore(str1,'com')}" />

<p>Final sub string : ${str2}</p>

</body>
</html>

Output :

Final sub string : www.c4learn.