I have a String called
String s = "Constitución GarantÃa";
I want to convert it to Constitución garantía
.
This is a Spanish keyword. How can I convert it?
I have a String called
String s = "Constitución GarantÃa";
I want to convert it to Constitución garantía
.
This is a Spanish keyword. How can I convert it?
What you have described is an XY problem. It's the encoding issue and there might appear more of the characters that need to be replaced. Instead of replacing them one by one, you need to encode the whole String to UTF-8
.
String s = "Constitución GarantÃa";
byte[] ptext = s.getBytes(StandardCharsets.ISO_8859_1);
String string = new String(ptext, StandardCharsets.UTF_8);
System.out.println(string); // Constitución Garantía
Consider fixing the encoding of a source where the string comes from before you actually start to work with it.