开发者

Converting hexadecimal string UTF-16 Perl internal representation [duplicate]

This question already has answers here: How can I decode UTF-16 data in Perl when I don't know the byte order? (3 answers) Closed 2 years ago.

I don't know why this code doesn't work:

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";

It prints out: "UTF-16:Unrecognised BOM a0 at /usr/lib/per开发者_JS百科l/5.10/Encode.pm line 174.".


Without a BOM (U+FEFF) at the start of the string to decode, there no way to know if 00 A0 is U+00A0 (UTF-16be) or U+0A00 (UTF-16le, used by Windows). One must specify the exact encoding when the BOM is absent. In this case, that's UTF-16be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜