Easy Tutorial
❮ Jstl Xml Parse Tag Jsp Life Cycle ❯

fn:replace() Function

JSP Standard Tag Library

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

Syntax

The syntax for the fn:replace() function is as follows:

${fn:replace(<original string>, <substring to be replaced>, <replacement string>)}

Example Demonstration

The following example demonstrates the functionality of this function:

<%@ 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" %>
<html>
<head>
<title>Using JSTL Functions</title>
</head>
<body>

&lt;c:set var="string1" value="I am from google"/>
&lt;c:set var="string2" value="${fn:replace(string1, 
                                'google', 'tutorialpro')}" />

<p>Replaced String : ${string2}</p>

</body>
</html>

The output is as follows:

Replaced String : I am from tutorialpro

JSP Standard Tag Library

❮ Jstl Xml Parse Tag Jsp Life Cycle ❯