免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4516 | 回复: 0

jython 中文问题解决方案 [复制链接]

论坛徽章:
0
发表于 2005-06-17 15:17 |显示全部楼层

# -*- coding: gb2312 -*-
FileInfo = """
#====================================================================
#========Project:  Jython Demo Gb2312
#========Module:  --
#========Author:  junsi
#========Create Date: 2005-06-14
#========Update Date:   
#====================================================================
"""
import string
import java.lang.String as jstring
def Unicode2Gb2312( astr ):
# type("") equal type( u"a") in jython
tmpstr = jstring( astr )
rtnstr = jstring ( tmpstr.getBytes("ISO8859_1"), "GB2312" )
if tmpstr.length() != rtnstr.length():
  return rtnstr
else:
  return astr
  
#
if __name__ == "__main__" :  
a = """
   如果我们不能改变这个世界,
   我们应该努力改变我们的生活.
   如果我们不能改变我们的生活,
   我们应该改变我们对生活的态度."""
   
ustr = """
   xc8xe7xb9xfbxcexd2xc3xc7xb2xbbxc4xdcxb8xc4xb1xe4xd5xe2xb8xf6xcaxc0xbdxe7,
   xcexd2xc3xc7xd3xa6xb8xc3xc5xacxc1xa6xb8xc4xb1xe4xcexd2xc3xc7xb5xc4xc9xfaxbbxee.
   xc8xe7xb9xfbxcexd2xc3xc7xb2xbbxc4xdcxb8xc4xb1xe4xcexd2xc3xc7xb5xc4xc9xfaxbbxee,
   xcexd2xc3xc7xd3xa6xb8xc3xb8xc4xb1xe4xcexd2xc3xc7xb6xd4xc9xfaxbbxeexb5xc4xccxacxb6xc8."""
print "Gb2312 coding string"
print a; print

print "Unicode2Gb2312 convert Gb2312 coding string"
print Unicode2Gb2312(a); print   

print "unicod stirng"
print ustr; print

print "Unicode2Gb2312 convert unicod stirng"
print Unicode2Gb2312(ustr); print


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6123/showart_31620.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP