2

I am Greek. When I search in my Contacts with substring "αυλ", all of these contacts match: "Παύλος", "Παυλίνα", "Αυλός".

So, Android match in letter "α" both letters "α" and "ά".

Is there an API for this feature, or I must code this the hard way? e.g.: string.replaceAll("ά", "α").replaceAll("έ", "ε").replaceAll(......) which is not so multilingual approach.

Chameleon
  • 1,406
  • 1
  • 11
  • 16

1 Answers1

1

The code from this link seems to be along the lines of what you want.

import java.text.Normalizer;
import java.util.regex.Pattern;

public String deAccent(String str) {
    String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD); 
    Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    return pattern.matcher(nfdNormalizedString).replaceAll("");
}

In recent versions of Java, some Unicode support was added with \p{Script=Greek}, \p{sc=Greek}, \p{IsGreek}, and \p{Greek}. You'll probably want to look into using these.

Community
  • 1
  • 1
Laurel
  • 5,522
  • 11
  • 26
  • 49