【问题标题】:remove accents with perl, using tr operator用 perl 删除重音,使用 tr 运算符
【发布时间】:2015-02-14 02:03:52
【问题描述】:

我正在尝试通过运行 perl 脚本来从文本中删除重音符号,在该脚本中我使用了 tr 运算符(我发现的更简单的方法):

我试过了:

tr/àâäéèëêîïôöûùüç/aaaeeeeiioouuuc/;

它删除了重音符号,但我得到了字符“aa”而不是“a”、“ae”而不是“e”等。

【问题讨论】:

  • 你能告诉我们产生奇怪输出的输入字符串吗?

标签: perl unicode ascii


【解决方案1】:

最好使用合适的模块,例如Text::Undiacritic =)

#!/usr/bin/perl
use warnings;
use strict;
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");

use Text::Undiacritic qw(undiacritic);

my $string = "C'est l'été à Paris ?\n";
print undiacritic $string;

输出:

C'est l'ete a Paris ?

注意

就您询问带有重音符号的字符串而言,undiacritic() 可以删除 重音符号,但在 typographic ligature 上不起作用。如果你传递字符串

C'est l'été à Paris Lætitia ?

它不会替代æ

欢迎来到真正棘手的世界:Unicode-UTF8。 A good pointer

【讨论】:

  • 对我来说听起来好像他的 utf8 数据没有这样标记;你能解决那部分吗?
猜你喜欢
  • 2013-05-24
  • 1970-01-01
  • 1970-01-01
  • 2012-05-04
  • 2011-04-02
  • 1970-01-01
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多