Latest web development tutorials

JSTL fn: endsWith () function

JSP Standard Tag Library JSP Standard Tag Library

fn: endsWith () adalah fungsi yang digunakan untuk menentukan apakah string diakhiri dengan akhiran tertentu.

tatabahasa

fn: () fungsi sintaks endsWith adalah sebagai berikut:

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

contoh Demo

Contoh berikut menunjukkan kemampuan fungsi ini:

<%@ 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 w3big 123"/>

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

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

</body>
</html>

Hasilnya adalah sebagai berikut:

字符串以 123 结尾

JSP Standard Tag Library JSP Standard Tag Library