JSTL Functions - split()

The fn:split() function splits a string into an array of substrings based on a delimiter string.

Syntax:

The fn:split() function has following syntax:

java.lang.String[] split(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="https://www.c4learn.com"/>
<c:set var="str2" value="${fn:split(str1,'/')}" />
<c:set var="str3" value="${fn:join(str2, '-')}" />
<p>Output String : ${str3}</p>
</body>
</html>

Output :

Output String : http:-www.c4learn.com