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

前端 未结 1 961
清酒与你
清酒与你 2020-12-11 21:58

I am looking for the way to normalise the list of titles. The title is normalized to be stored in a database as a sort and look up key. \"Normalize\" means many things such

相关标签:
1条回答
  • 2020-12-11 22:38

    You can use java.text.Normalizer which comes close to normalizing Strings in Java. Though regex are also a powerful way to manipulate the 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

    0 讨论(0)
提交回复
热议问题