0

I have an app working as webservice for a webpage and when an string arrives with stress like á, é, í, ó or ú the Java app shows the letter without the stress and a question mark like instead of showing ó in appears o?

I tried with:

return Normalizer.normalize(original, Normalizer.Form.NFD).toLowerCase().replaceAll("\\s+","").replace("?","").replace("á","a").replace("é","e").replace("ó","o").replace("ú","u").replace("í","i").replace("ñ","n");

Or

return original.toLowerCase().replaceAll("\\s+","").replace("?","").replace("á","a").replace("é","e").replace("ó","o").replace("ú","u").replace("í","i").replace("ñ","n");

When I debug the app, the string arrives with the stress in the right way, but then when I print it in the console or save it in the database it appears with the question mark.

I'm using Spring as framework.

When consuming the backend, I'm using the following Content-Type application/json; charset=UTF-8.

The database is latin1-default colection, I changed to UTF8 but I get the same result.

Faabass
  • 1,394
  • 8
  • 29
  • 58
  • Most likely there is an encoding problem somewhere along the way. – Tim Biegeleisen Jul 19 '17 at 01:58
  • 3
    This char is a UTF8 char, maybe your console does not have the ability to print it out. Maybe your DB is not setup for UTF8. But I am not sure why you are trying to `replace` it – Scary Wombat Jul 19 '17 at 01:59
  • What frameworks are you using, if any? Also, what @ScaryWombat said. – Abhijit Sarkar Jul 19 '17 at 02:00
  • [An easy way to remove stressed vocals in Java](https://stackoverflow.com/q/15190656/335858) – Sergey Kalinichenko Jul 19 '17 at 02:05
  • Well all strings in Java are UTF-16 encoded. To test if your strings have the correct value you also need a console to support the characters. I don't know about the Windows console, but AFAIK it is bad. I have seen smart people use cmder console on windows, maybe that helps you debug if your strings have to correct value. What also might be the problem is, that the source file you write is in a different encoding than the Java Compiler thinks. – Arne Jul 19 '17 at 12:37

0 Answers0