Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Non-ASCII code to ASCII equivalent in terms of look

I have thousands of name in a mysql database that have the extended ASCII code in them. I want to convert them to a normal english alphabet. Here is an example :

Indāpur Jejūri convert to -> Indapur Jejuri

So how can I do it ? I know Java and Groovy, and a bunch of other scripting languages but didn't have much luck. Any suggestion ?

like image 212
AlexCon Avatar asked Nov 14 '25 18:11

AlexCon


1 Answers

I found the answer after going through many posts in stackoverflow : Converting Symbols, Accent Letters to English Alphabet

import java.text.Normalizer;
import java.util.regex.Pattern;

public String deAccent(String str) {
    String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD); 
    Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    return pattern.matcher(nfdNormalizedString).replaceAll("");
}
like image 64
AlexCon Avatar answered Nov 17 '25 07:11

AlexCon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!