0

I try to convert a String with special letters (such as ä,à,è,ç,î,ñ.ö ect.) to ascii letters. My example:

String newName = oldName.replaceAll("\\s","").replaceAll("[^a-zA-Z0-9]", "");

This works fine, except that all special letters disappear... Is there an easy way to "convert" these letters to the ascii format?

For example "François Müdé" would become "francoismuede". How should I implement this?

muffin
  • 1,336
  • 4
  • 19
  • 43
  • 3
    You can try using java.text.Normalizer.normalize(). This function offers services regarding strings normalization for Unicode. See this question: http://stackoverflow.com/questions/1008802/converting-symbols-accent-letters-to-english-alphabet – Alberto Spelta Jun 05 '13 at 09:07

1 Answers1

1

Generally speaking, ASCII is very poor and old character table and it actually doesn't contain wanted characters.

But what about your issue, it isn't related to ASCII table. Java works with unicode. Just what you need is include such symbols into your regexp, something like [^a-zA-Z0-9äàèçîñö].

The core problem is that such regular constructions as a-z or A-Z (called symbol classes) don't include such special national symbols. You have to include them manually.

Andremoniy
  • 31,241
  • 14
  • 110
  • 218