4

How do I convert Æ and á into a regular English char with Java ? What I have is something like this : Local TV from Paraná. How to convert it to [Parana] ?

Frank
  • 30,590
  • 58
  • 161
  • 244

3 Answers3

6

Look at icu4j or the JDK 1.6 Normalizer:

public String removeAccents(String text) {
    return Normalizer.normalize(text, Normalizer.Form.NFD)
                     .replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
GAMA
  • 5,958
  • 14
  • 79
  • 126
bmargulies
  • 97,814
  • 39
  • 186
  • 310
0

As far as I know, there's no way to do this automatically -- you'd have to substitute manually using String.replaceAll.

String str = "Paraná";
str = str.replaceAll("á", "a");
str = str.replaceAll("Æ", "a");
Kaleb Brasee
  • 51,193
  • 8
  • 108
  • 113
0

Try something similar to the following code snippet:

import org.apache.commons.lang3.StringUtils;

public class Test {
    public static void main(String[] args) {

        String original = new String("Ramesh Öhrman");
        try {
            
            System.out.println(StringUtils.stripAccents(original));
            
        } catch (Exception e) {
        }
        
    }
}

Output: Ramesh Ohrman

Elikill58
  • 4,050
  • 24
  • 23
  • 45