天天看点

JSTL提供的函数标签操作EL表达式字的符串

在jsp页面导入标签

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

(1)转换字符串大小写:

tolowercase("要截取的字符串"):${fn:tolowercase("hello,word!")}

touppercase("要截取的字符串"):${fn:touppercase("hello,word!")}

(2)截取字符串:

substring("原字符串",开始的索引,结束的索引)

截取字符串:${fn:substring("hello,word!",0,5)}

substringafter("原字符串","索引串")

取索引串之后的内容:${fn:substringafter("hello,word!","hello,") }

substringbefore("原字符串","索引串")

取索引串之前的内容:${fn:substringbefore("hello,word!","word!") }

若字符串中未包含索引串,返回空字符串。

(3)去空格:

trim("原字符串")

去掉字符串前后的空格:${fn:trim("   hello,word!   ")}

(4)替换字符:

replace("原字符串","要替换的字符","替换后的字符")

替换字符:${fn:replace("hello,word!","word","你好")}

(5)字符串匹配查找:

indexof("字符串","子字符串")返回int

求字符串第一次出现的下标:${fn:indexof("hello,word!",",")}

startswith("字符串1","字符串2")返回boolean

判断一个字符串是否已另一个字符串开头:${fn:startswith("hello,word","h") }

endswith("字符串1","字符串2")返回boolean

判断一个字符串是否已另一个字符串结尾:${fn:endswith("hello,word","h") }

contains("字符串1","字符串2")返回boolean

判断一个字符串是否包含另一个字符串:${fn:contains("hello,word","hello") }

containsignorecase("字符串1","字符串2")返回boolean

判断一个字符串是否包含另一个字符串,不区分大小写:${fn:containsignorecase("hello,word","w") }

(6)拆分、合并字符串

split("原字符串","拆分的分界符")

把字符串拆分成数组:${fn:split("hello,word!",",")}

join("字符串数组","组合后的分隔符")

${fn:join(strarray,"|")}

(7)将字符串中的xml符号转换成实体符号:

escapexml("要转换的字符串")

不解析xml标签:${fn:escapexml("<b>hello,word!</b>")}

(8)计算字符串长度

length("字符串")返回int

求字符串的长度:${fn:length("hello,word!")}

原帖地址:http://wolfgangkiefer.blog.163.com/blog/static/86265503201151594119474/