14 Şubat 2013 Perşembe

Using java.text.Normalizer to convert accents to regular string

I had to send SMS in Java application, and the message consists of a name parameter like Alkın TÖŞDÖĞEN. This is a Turkish word so it is not properly displayed in message.

The first solution in everyone's mind is I think to use .replaceAll("Ö", "O").replaceAll("ı", "i")..

But here is a simpler way :

public static String convertToRegular(String aOriginal) {
        return (Normalizer.normalize(aOriginal, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]",""));     
 }

Normalizer separates accents. ReplaceAll replaces all non-regular characters with empty characters.




http://stackoverflow.com/questions/3322152/java-getting-rid-of-accents-and-converting-them-to-regular-letters

Paylaşım

Benzer Kayıtlar


0 Yorum
:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng
:lv

Blogger tarafından desteklenmektedir.