fn:endsWith()-Funktion

JSP 标准标签库JSP-Standard-Tag-Bibliothek

Die Funktion fn:endsWith() wird verwendet, um zu bestimmen, ob eine Zeichenkette mit einem angegebenen Suffix endet.

Syntax

Die Syntax der Funktion fn:endsWith() ist wie folgt:

<c:if test="${fn:endsWith(<原始字符串>, <要查找的子字符串>)}">
...
</c:if>

Beispiel-Demonstration

Das folgende Beispiel demonstriert die Funktionsweise dieser Funktion:

<%@ 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="theString" value="I am from example 123"/>

<c:if test="${fn:endsWith(theString, '123')}">
   <p>字符串以 123 结尾<p>
</c:if>

<c:if test="${fn:endsWith(theString, 'unoob')}">
   <p>字符串以 example 结尾<p>
</c:if>

</body>
</html>

Die Ausgabe sieht wie folgt aus:

字符串以 123 结尾

JSP 标准标签库JSP-Standard-Tag-Bibliothek

Andere Erweiterungen