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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -