English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Função fn:replace() do JSTL

Biblioteca de Tags Padrão JSP

A função fn:replace() substitui todas as substrings especificadas por outra string no texto.

fn:replace()

Sintaxe

${fn:replace(<string original>, <string a ser substituída>, <string a substituir>)}

Exemplo de Demonstração

A seguir está um exemplo que demonstra a função dessa:

<%@ 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>Uso de funções JSTL</<title>
</<head>
<body>
<c:set var="string1" value="I am from google"/>
<c:set var="string2" value="${fn:replace(string1, 
                                'google', 'w3codebox}" />
<p>String substituída: ${string2}<//p>
</body>
</html>

Resultados da execução a seguir:

String substituída: I am from w3codebox

Biblioteca de Tags Padrão JSP