fn:startsWith()函數
fn:startsWith()函數用於確定一個字串是否以指定的首碼開始。
語法
fn:startsWith()函數的語法如下:
<c:if test="${fn:startsWith(<原始字串>, <搜索的首碼>)}"> ... </c:if>
實例演示
以下實例演示了這個函數的功能:
<%@ 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="string" value="zaixian: I am from zaixian."/> <c:if test="${fn:startsWith(string, 'Google')}"> <p>字串以 Google 開頭</p> </c:if> <br /> <c:if test="${fn:startsWith(string, 'zaixian')}"> <p>字串以 zaixian 開頭</p> </c:if> </body> </html>
運行結果如下:
字串以 zaixian 開頭