将ä,ö,ü重命名为ae,oe,ue [英] Rename ä, ö, ü to ae, oe, ue

查看:170
本文介绍了将ä,ö,ü重命名为ae,oe,ue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们要重命名字符串,以使像德国变音符之类的奇怪字符被转换为它们的官方非变音符表示形式。在Java中,是否有一些函数可以转换此类字符(也称为AMAP处理映射),不仅可以转换为德语变音符号,还可以转换为法语,捷克语或斯堪的纳维亚字符?原因是创建一个函数,该函数可以重命名Subversion在不同平台上可以毫无问题地处理的文件/目录。

We want to rename strings that way that "strange" characters like German umlauts are translated to their official non-umlaut representation. In Java, is there some function to convert such characters (AKA handle the mapping), not only for the German umlauts, but also for French, Czech or Scandinavian characters? The reason is to create a function that could rename files/directories that could be handled without problems on different platforms by Subversion.

这个问题类似,但是没有有用的答案。

This question is similar but without a useful answer.

推荐答案

您可以使用Unicode块属性 \p {InCombiningDiacriticalMarks} 从字符串中删除(大多数)变音符:

You can use the Unicode block property \p{InCombiningDiacriticalMarks} to remove (most) diacritical marks from Strings:

public String normalize(String input) {
  String output = Normalizer.normalize(input, Normalizer.Form.NFD); 
  Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");

  return pattern.matcher(output).replaceAll("");
}

不过,这不会取代德国变音符。它将ö变成 o ä变成 a 等。但这也许对你也没关系。

This will not replace German umlauts the way you desire, though. It will turn ö into o, ä into a and so on. But maybe that's okay for you, too.

这篇关于将ä,ö,ü重命名为ae,oe,ue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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