fn:split(string, separator) 具体使用方法
来源:互联网 发布:mac迅雷下载不了种子 编辑:程序博客网 时间:2024/05/19 05:38
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html> <head> <title>Example fn:split and fn:join tag of JSTL</title> </head> <body> <c:set var="str1" value="This is first string"/> <c:set var="str2" value="This|is|second|string"/> <c:set var="str3" value="This|is+third*string"/>
<h4>tag fn:split(Here we will split the given string in to array of string on the <br>basis of given delimeter)</h4> <table width="50%" border="1"> <tr> <th>Input String</th> <th>Delimiter(s)</th> <th>After split</th> </tr> <tr> <td>${str1}</td> <td>white space</td> <td> <c:forEach var="num" items="${fn:split(str1, ' ')}"> <c:out value="${num}" /> </c:forEach> </td> </tr>
<tr> <td>${str2}</td> <td>|</td> <td> <c:forEach var="num" items="${fn:split(str2, '|')}"> <c:out value="${num}" /> </c:forEach> </td> </tr>
<tr> <td>${str3}</td> <td>+|*</td> <td> <c:forEach var="num" items="${fn:split(str3, '+|*')}"> <c:out value="${num}" /> </c:forEach> </td> </tr </table>
<h4>tag fn:split(Here we will join the splitted array of string in to a single string <br>with the given separator)</h4> <table cellpadding="5" border="1"> <tr> <th>Separator</th> <th>After join</th> </tr> <tr><c:set var="a1" value="${fn:split(str1, ' ')}" /> <td> white space</td> <td><c:out value="${fn:join(a1, ' ')}" /></td> </tr> <tr><c:set var="a1" value="${fn:split(str2, '|')}" /> <td>|</td> <td><c:out value="${fn:join(a1, ' | ')}" /></td> </tr> <tr><c:set var="a1" value="${fn:split(str3, '|+*')}" /> <td>***</td> <td><c:out value="${fn:join(a1, ' *** ')}" /></td> </tr> </table> </body></html>