3

I want to match two strings with Unicode encoding in Java. I want to match something like:

"asdfeo"
"ásdfeó"

How can I return 0 in the compareTo() method?


EDIT:

When I type a string into an autocomplete view without diacritics (for some reason I don't have the keyboard to write those diacritics), I want to see between the autocomplete suggestions the objects with diacritics. That is why I want to overwrite the compareTo() method.

overbet13
  • 1,654
  • 1
  • 20
  • 36
  • http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net – Anders Lindahl May 02 '12 at 09:19
  • 2
    @bicska88: What do you want to achieve with this? – Aaron Digulla May 02 '12 at 09:22
  • 3
    What Aaron is asking is *the most important question* here. There are several ways to (kind-of) do what you ask and which one to choose depends on what *exactly* you try to achieve with this. The diacritics are not just "funny things that hang on characters", they actually *matter* in most languages where they are used. Sometimes *a lot*. Removing/ignoring them is *usually* not the best choice. – Joachim Sauer May 02 '12 at 09:24
  • @JoachimSauer there you have the motivation, Mister. – overbet13 May 02 '12 at 09:30
  • 1
    @bicska88: that's a good reason. Don't get me wrong: I don't try to "police" this issue, it's just that different motivations might require different solutions (and some might even require an entirely different approach). – Joachim Sauer May 02 '12 at 09:31
  • @JoachimSauer exactly. Please don't get me wrong either. – overbet13 May 02 '12 at 09:34

1 Answers1

5

What you are looking for is the Collator API.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436