fn:replace()
函數使用一個字串替換字串的所有指定出現子字串。
語法
fn:replace()
函數具有以下語法 -
boolean replace(java.lang.String, java.lang.String, java.lang.String)
示例
以下示例將顯示如何使用fn:replace()
函數,編寫一個JSP檔:fn_replace.jsp 如下所示:
<%@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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jstl fn:replace()函數</title>
</head>
<body>
<div style="margin: auto; width: 90%">
<h2>fn:replace()函數示例</h2>
<hr />
<c:set var="string1" value="This tutorials from xuhuhu.com" />
當前字串:<c:out value="${string1}"/>
<c:set var="string2" value="${fn:replace(string1, '.com', '.cn')}" />
<p>替換後: ${string2}</p>
</div>
</body>
</html>
運行上述專案代碼,得到以下結果如下 -
上一篇:
Jstl教學
下一篇:
JSP+MySQL實例