fn:indexOf()詳解(jsp中JSTL標簽庫)


 

fn:indexOf()函數返回一個字符串中指定子串的位置。

語法

fn:indexOf()函數的語法如下:

${fn:indexOf(<原始字符串>,<子字符串>)}

實例演示

以下實例演示了這個函數的功能:

<%@ 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>Using JSTL Functions</title> </head> <body> <c:set var="string1" value="This is first String."/> <c:set var="string2" value="This <abc>is second String.</abc>"/> <p>Index (1) : ${fn:indexOf(string1, "first")}</p> <p>Index (2) : ${fn:indexOf(string2, "second")}</p> </body> </html>

=================================================================

運行結果如下:

Index (1) : 8 Index (2) : 13


=================================================================
    • 函數名 函數說明 使用舉例   
    • fn:contains 判定字符串是否包含另外一個字符串 <c:if test="${fn:contains(name, searchString)}">  
    • fn:containsIgnoreCase 判定字符串是否包含另外一個字符串(大小寫無關) <c:iftest="${fn:containsIgnoreCase(name, searchString)}">  
    • fn:endsWith 判定字符串是否以另外字符串結束 <c:if test="${fn:endsWith(filename, ".txt")}">  
    • fn:escapeXml 把一些字符轉成XML表示,例如 <字符應該轉為< ${fn:escapeXml(param:info)}   
    • fn:indexOf 子字符串在母字符串中出現的位置 ${fn:indexOf(name, "-")}   
    • fn:join 將數組中的數據聯合成一個新字符串,並使用指定字符格開 ${fn:join(array, ";")}   
    • fn:length 獲取字符串的長度,或者數組的大小 ${fn:length(shoppingCart.products)}   
    • fn:replace 替換字符串中指定的字符 ${fn:replace(text, "-", "•")}   
    • fn:split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")}   
    • fn:startsWith 判定字符串是否以某個子串開始 <c:if test="${fn:startsWith(product.id, "100-")}">  
    • fn:substring 獲取子串 ${fn:substring(zip, 6, -1)}   
    • fn:substringAfter 獲取從某個字符所在位置開始的子串   
    • ${fn:substringAfter(zip, "-")}   
    • fn:substringBefore 獲取從開始到某個字符所在位置的子串 ${fn:substringBefore(zip, "-")}   
    • fn:toLowerCase 轉為小寫 ${fn.toLowerCase(product.name)}   
    • fn:toUpperCase 轉為大寫字符 ${fn.UpperCase(product.name)}   
    • fn:trim 去除字符串前后的空格 ${fn.trim(name)} 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM