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

La fonction fn:endsWith() de JSTL

Bibliothèque de balises standard JSP

La fonction fn:endsWith() est utilisée pour déterminer si une chaîne de caractères se termine par un suffixe spécifique.

Syntaxe

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

<c:if test="${fn:endsWith(<chaîne originale>, <sous-chaîne à trouver>)}">
...
</c:if>

Exemple de démonstration

Voici un exemple qui montre la fonctionnalité de ce fonction :

<%@ 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 JSTL</title>
</head>
<body>
<c:set var="theString" value="I am from w3codebox 123"/>
<c:if test="${fn:endsWith(theString, '123')}">
   <p>Une chaîne de caractères commence par 123 Fin<p>
</c:if>
<c:if test="${fn:endsWith(theString, 'hooo')}">
   <p>Une chaîne de caractères commence par w3codebox Fin<p>
</c:if>
</body>
</html>

Résultat de l'exécution suivant :

Une chaîne de caractères commence par 123 Fin

Bibliothèque de balises standard JSP