0
I have the following code snippet for special character replacement
public String removerAcentos(String str) {
return Normalizer.normalize(str.replaceAll(" ", ""), Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
}
When running on my machine(windows) it works perfectly for my goal.
ex: Parametro = "SAGRADO CORAÇÃO" retorno = "SAGRADOCORACAO"
When I run the method by requesting the server the following happens:
ex: Parametro = "SAGRADO CORAÇÃO" retorno = "SAGRADOCORAO"
Special characters are removed from the string
Can anyone tell me why, is any solution ?
It must be getting the default Cultureinfo server you must configure in your application, if your local system is in Pt the server must be in EN
– Marco Vinicius Soares Dalalba
This part of REGEX does just that
replaceAll("[^\\p{ASCII}]", "")
, anything he doesn’t consider asASCII
will be removed, not replaced. This way you should check, as said by @Marcoviniciussoaresdalalba, what he considersASCII
– Guilherme Lautert
POSIX groups shall comply with Unicode case Folding only when the flag
(?U)
is used. If you are not on Android,.replaceAll("\\P{ASCII}+", "")
shall function to remove all non-ASCII characters. See https://docs.oracle.com/javase/7/docs/api/java/utix/regex/Pattern.html#ubpc– Mariano