Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java unicode comparison [duplicate]

Possible Duplicates:
Java. Ignore accents when comparing strings
Java string searching ignoring accents

Hi All

I need to compare strings in java that might be like 'Chloe' and 'Chloé'. I need them to be equal. Anyone knows what the best practice is ? Or is there some third-party library ?

Roman

like image 293
Roman Avatar asked Nov 29 '10 11:11

Roman


1 Answers

Have a look at International Components for Unicode, it can do what you need.

Edit: here's some sample code to get you started (from the Collator Javadoc):

// Get the Collator for US English and set its strength to PRIMARY
Collator usCollator = Collator.getInstance(Locale.US);
usCollator.setStrength(Collator.PRIMARY);
if (usCollator.compare("abc", "ABC") == 0) {
  System.out.println("Strings are equivalent");
}
like image 79
Tassos Bassoukos Avatar answered Sep 20 '22 22:09

Tassos Bassoukos