DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Tradução De Caracteres ASCII Especiais Para Entidades HTML
Código responsável por traduzir caracteres ASCII especiais para entidades HTML
def str =
"""Ãrido
estrambólico
cabriocárico
retumbante
sequências"""
// site com tabela de referência : http://www.icmc.usp.br/ensino/material/html/especiais.html
def map = ["á":"á","Ã":"Á","â":"â","Â":"Â","à ":"à","À":"À",
"ã":"ã","Ã":"Ã","ç":"ç","Ç":"Ç","é":"é","É":"É",
"ê":"ê","Ê":"Ê","Ã":"í","Ã":"Í","ó":"ó","Ó":"Ó",
"ô":"ô","Ô":"Ô","õ":"õ","Õ":"Õ","ú":"ú","Ú":"ÚA;" ]
def newStr = ""
for(i in 0..(str.length()-1)) {
def key = str.charAt(i).toString()
newStr += map.containsKey(key) ? map.get(key) : key
}
println newStr





