在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/