EL表达式截取字符串 |
在项目中遇到了只要求显示用户的姓,同时前台jsp页面用的是el表达式,这时就用到了el截取字符串的函数。
以下是我查到的几个常用的函数。
函数名 | 函数说明 | 使用举例 |
---|---|---|
fn:contains | 判定字符串是否包含另外一个字符串 | <c:if test="${fn:contains(name, searchString)}"> |
fn:contains | 判定字符串是否包含另外一个字符串(大小写无关) | <c:if test="${fn:containsIgnoreCase(name, searchString)}"> |
fn:endsWith | 判定字符串是否以另外字符串结束 | <c:if test="${fn:endsWith(filename, “.txt”)}"> |
fn:join | 将数组中的数据联合成一个新字符串,并使用指定字符格开 | ${fn:join(array, “;”)} |
fn:length | 获取字符串的长度,或者数组的大小 | ${fn:length(shoppingCart.products)} |
fn:replace | 替换字符串中指定的字符 | ${fn:replace(text, “-”, “& #149;”)} |
fn:split | 把字符串按照指定字符切分 | ${fn:split(customerNames, “;”)} |
fn:substring | 获取子串 | ${fn:substring(zip, 6, -1)} |
fn:substringAfter | 获取从某个字符所在位置开始的子串 | ${fn:substringAfter(zip, “-”)} |
fn:toLowerCase | 转为小写 | ${fn.toLowerCase(product.name)} |
fn:toUpperCase | 转为大写 | ${fn.UpperCase(product.name)} |
fn:trim | 去除字符串前后的空格 | ${fn.trim(name)} |
我在这里用的是获取字符串的子串