我有一个像这样的字符串:
Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t
Work After Installing IE7 St\xc3\xa5le
我通过读取 XML 文件得到。这是一个 UTF-8 字符串。现在我想打印其等效的 unicode 字符,以便得到:
Why RUNAS Windows Explorer Doesn’t Work After Installing IE7 Ståle
我尝试了一个小程序:
use strict;
use utf8;
use Encode;
my $str = "Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t Work After Installing IE7 St\xc3\xa5le";
print $str;
它奏效了!!
问题是当我试图从文件中读取字符串时,它没有转换。所以以下不会产生 unicode 输出:
use strict;
use utf8;
use Encode;
my $str = <DATA>;
$str = decode("utf8", $str);
open OUT, ">", "o.txt" or die;
binmode(OUT,":utf8");
print OUT $str;
__DATA__
Why RUNAS Windows \xee\x80\x80\x45xplorer\xee\x80\x81 Doesn\xe2\x80\x99t Work After Installing IE7 St\xc3\xa5le