Latest web development tutorials

JSTL fn: split () function

JSP Standard Tag Library JSP Standard Tag Library

fn: split () function to split a string as a substring of the array with the specified delimiter.

grammar

fn: () syntax split function is as follows:

${fn:split(<带分隔符的字符串>, <分隔符>)}

Examples Demo

The following examples demonstrate the capabilities of this 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>使用 JSTL 函数</title>
</head>
<body>

<c:set var="string1" value="www w3big com"/>
<c:set var="string2" value="${fn:split(string1, ' ')}" />
<c:set var="string3" value="${fn:join(string2, '-')}" />

<p>string3 字符串 : ${string3}</p>

<c:set var="string4" value="${fn:split(string3, '-')}" />
<c:set var="string5" value="${fn:join(string4, ' ')}" />

<p>string5 字符串: ${string5}</p>

</body>
</html>

Results are as follows:

string3 字符串 : www-w3big-com

string5 字符串: www w3big com

JSP Standard Tag Library JSP Standard Tag Library