从外观上将非ASCII代码转换为等效的ASCII [英] Converting Non-ASCII code to ASCII equivalent in terms of look

查看:109
本文介绍了从外观上将非ASCII代码转换为等效的ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql数据库中有成千上万的名称,其中包含扩展的ASCII代码.我想将它们转换为普通的英文字母.这是一个示例:

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

那我该怎么办呢?我知道Java和Groovy,以及其他许多脚本语言,但是运气不高.有什么建议吗?

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 ?

推荐答案

我在浏览了stackoverflow中的许多帖子后找到了答案:

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

这篇关于从外观上将非ASCII代码转换为等效的ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆