string - What is the equivalent of stringByFoldingWithOptions:locale: in Java? -


i looking way normalise list of titles. title normalized stored in database sort , key. "normalize" means many things such converting lowercase, removing roman accent character, or removing preceding "the", "a" or "an".

in ios or mac, nsstring class has stringbyfoldingwithoptions:locale: method folding version of string.

nsstring class reference - stringbyfoldingwithoptions:locale:

in java, java.uril.collator class seems useful comparing, there seems no way convert such purpose.

you can use java.text.normalizer comes close normalizing strings in java. though regex powerful way manipulate strings in whichever way possible.

example of accent removal:

string accented = "árvíztűrő tükörfúrógép"; string normalized = normalizer.normalize(accented,  normalizer.form.nfd); normalized = normalized.replaceall("[^\\p{ascii}]", "");  system.out.println(normalized); 

output:

arvizturo tukorfurogep 

more explanation here: http://docs.oracle.com/javase/tutorial/i18n/text/normalizerapi.html


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -