【问题标题】:Converting hexadecimal string UTF-16 Perl internal representation [duplicate]转换十六进制字符串 UTF-16 Perl 内部表示 [重复]
【发布时间】:2011-02-17 19:09:35
【问题描述】:

我不知道为什么这段代码不起作用:

use strict;
use warnings;
use Encode qw/decode/;
my $entity_unicode = "00A0";
$entity_unicode = decode("UTF-16", pack('H4', $entity_unicode));
print $entity_unicode, "\n";

它打印出:“UTF-16:Unrecognized BOM a0 at /usr/lib/perl/5.10/Encode.pm line 174.”。

【问题讨论】:

    标签: perl unicode utf-16


    【解决方案1】:

    如果要解码的字符串开头没有 BOM (U+FEFF),则无法知道 00 A0 是 U+00A0 (UTF-16be) 还是 U+0A00 (UTF-16le,Windows 使用) .当 BOM 不存在时,必须指定确切的编码。在这种情况下,就是 UTF-16be。

    【讨论】:

      猜你喜欢
      • 2016-12-27
      • 2010-11-16
      • 2020-01-18
      • 2020-10-26
      • 2012-06-27
      • 2011-05-15
      • 2018-07-03
      • 2018-01-22
      • 1970-01-01
      相关资源
      最近更新 更多