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

感情迁移 提交于 2019-12-24 11:09:04

问题


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 ?


回答1:


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("");
}


来源:https://stackoverflow.com/questions/22599703/converting-non-ascii-code-to-ascii-equivalent-in-terms-of-look

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!