JSTL Functions – replace()



The fn:replace() function replaces all occurrences of a string with another string.

Syntax:

The fn:replace () function has following syntax:

boolean replace(java.lang.String, java.lang.String, java.lang.String)

JSTL Example :

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

<html>
<head>
<title>JSTL Tutorial</title>
</head>
<body>

<c:set var="str1" value="http://www.c4learn.com"/>
<c:set var="str2" value="${fn:split(str1,'/')}" />
<c:set var="str3" value="${fn:replace(str1,'c4learn','google')}" />

<p>Final String : ${str3}</p>

</body>
</html>

Output :

Final String : http://www.google.com