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

Fonction fn:split() de JSTL

Bibliothèque de balises standard JSP

fn:split() La fonction divise une chaîne en un tableau de sous-chaînes en utilisant le séparateur spécifié.

Syntaxe

La syntaxe de la fonction fn:split() est la suivante :

${fn:split(<string à séparer>, <separateur>)}

Exemple de démonstration

Voici un exemple pour démontrer la fonction de ce filtre :

<%@ 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>Utilisation des fonctions de JSTL</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 Chaîne : ${string3}<//p>
<c:set var="string4" value="${fn:split(string3, '-)}" />
<c:set var="string5" value="${fn:join(string4, ' '}" />
<p>string5 Chaîne: ${string5}<//p>
</body>
</html>

Résultat de l'exécution suivant :

string3 Chaîne : www-w3codebox-com
string5 Chaîne: www w3codebox com

Bibliothèque de balises standard JSP