English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JSTL fn:split() function

JSP Standard Tag Library

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

Syntax

The syntax of fn:split() function is as follows:

${fn:split(<The string to be separated>, <Separator>)}

Example Demonstration

The following example demonstrates the function:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
<%@ 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>Using JSTL Functions</title>
</head>
<body>
<c:set var="string1" value="www w3codebox com"/>
<c:set var="string2" value="${fn:split(string1, ' />
<c:set var="string3" value="${fn:join(string2, '-}" />
<p>string3 String: ${string3}<//p>
<c:set var="string4" value="${fn:split(string3, '-}" />
<c:set var="string5" value="${fn:join(string4, ' />
<p>string5 String: ${string5}<//p>
</body>
</html>

The running result is as follows:

string3 String: www-w3codebox-com
string5 String: www w3codebox com

JSP Standard Tag Library