免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3508 | 回复: 7
打印 上一主题 下一主题

怎么把utf ->gb2312 and gb2312 -> utf [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-03 11:54 |只看该作者 |倒序浏览
怎么把utf ->;gb2312 and gb2312 ->; utf

两种编码格式的互相转换,

具体的实现方法!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-03-03 17:24 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);

# Convert a string in 'gb2312' to 'UTF8'
my $output = to_utf8({ -string =>; 'An example', -charset =>; 'gb2312' });


# Convert a string in 'UTF8' encoding to encoding 'gb2312'
my $other  = from_utf8({ -string =>; 'Other text', -charset =>; 'gb2312' });
=========================================
上面是參考CPAN 的說明..
試試看上面這個module,如果不行再用下面的方式設定新的charset
,注意Unicode::MapUTF8必須要上search.cpan.org抓下來..
Try It....如果是Perl 5.8以上,default有個encode的module..
怎麼用請自行研究..我沒用過..
=========================================
# List available character set encodings
my @character_sets = utf8_supported_charset;

# Add a character set alias
utf8_charset_alias({ 'ms-japanese' =>; 'sjis' });

# Convert between two arbitrary (but largely compatible) charset encodings
# (SJIS to EUC-JP)
my $utf8_string   = to_utf8({ -string =>;$sjis_string, -charset =>; 'sjis'});
my $euc_jp_string = from_utf8({ -string =>; $utf8_string, -charset =>; 'euc-jp' })

# Verify that a specific character set is supported
if (utf8_supported_charset('ISO-8859-1') {
     # Yes
}

论坛徽章:
0
3 [报告]
发表于 2003-03-04 10:19 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

我听说台湾有位专家写了关于编码互相转换模块,不止到那里有?还有我看到perl5.8里面有个Encode模块,是不是可以用?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2003-03-04 11:10 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

http://www.cpan.org 上一定可以找得到..
perl 5.8以上支援Unicode...你可以用
Encode module 來轉碼..
但是我沒用過..所以請去 http://search.cpan.org
上找online document看看怎麼用..
或者直接在機器上輸入
perldoc  Encode
看online document...
基本上..我沒用過這個module...
不然就是我提過的那個module也可以用...

论坛徽章:
0
5 [报告]
发表于 2003-03-04 14:33 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

看来我只好自己试了!

论坛徽章:
0
6 [报告]
发表于 2003-03-11 03:46 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

可以看看 cpan.org 上唐宗汉的模块与相关文章哟

perl 5.8 就是唐宗汉译为中文的。

论坛徽章:
0
7 [报告]
发表于 2003-03-11 17:41 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

use XML::LibXML;
     encodeToUTF8

         $encodedstring = encodeToUTF8( $name_of_encoding, $sting_to_encode );

     decodeFromUTF8

         $decodedstring = decodeFromUTF8($name_of_encoding, $string_to_decode );

论坛徽章:
0
8 [报告]
发表于 2003-03-11 17:43 |只看该作者

怎么把utf ->gb2312 and gb2312 -> utf

Perl 5 计算UTF-8长度似乎有问题!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP