Character removal on Heroku server

Asked

Viewed 37 times

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 ?

  • 2

    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

  • This part of REGEX does just that replaceAll("[^\\p{ASCII}]", ""), anything he doesn’t consider as ASCII will be removed, not replaced. This way you should check, as said by @Marcoviniciussoaresdalalba, what he considers ASCII

  • 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

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.