Skip to content

Files

Latest commit

5142ebd · Oct 15, 2019

History

History
39 lines (28 loc) · 1.45 KB

25.md

File metadata and controls

39 lines (28 loc) · 1.45 KB

fn:endsWith() - JSTL 函数

原文: https://beginnersbook.com/2013/12/fn-endswith-jstl-function/

fn:endsWith()函数用于检查字符串的后缀。它检查给定的字符串是否以特定字符串结尾。检查是区分大小写的。

语法

boolean fn:endsWith(input_string, suffix_string)

它验证input_string是否以suffix_string结尾。如果测试成功,则函数返回true,否则它给false。函数的返回类型是boolean,它接收两个字符串作为参数。

注意:它在进行检查时考虑了大小写。

fn 的例子:endsWith()

在示例中,我们有一个输入字符串"BeginnersBook.com"和另外 4 个字符串。我们正在验证输入字符串是否以给定的四个字符串结束。

<%@ 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 fn:endsWith() example</title>
</head>
<body>
String ends with ".com": ${fn:endsWith("BeginnersBook.com", "com")}
<br>String ends with "book.com": ${fn:endsWith("BeginnersBook.com", "book.com")}
<br>String ends with "Book.com": ${fn:endsWith("BeginnersBook.com", "Book.com")}
<br>String ends with "Book.co": ${fn:endsWith("BeginnersBook.com", "Book.co")}
</body>
</html>

输出:

fn-endsWith-example