这个是python的,如果是RUBY,如何转化这种字符:帮 ,有没有unichr什么的?:
[code="python"]
!/usr/bin/env python
-*- coding: utf-8 -*-
import re
str='帮助'
def unistr(m):
return unichr(int(m.group(0)[2:-1]))
print re.sub(r'&#[0-9]{5};',unistr,str)
[/code]
这个是python的,如果是RUBY,如何转化这种字符:帮 ,有没有unichr什么的?:
[code="python"]
!/usr/bin/env python
import re
str='帮助'
def unistr(m):
return unichr(int(m.group(0)[2:-1]))
print re.sub(r'&#[0-9]{5};',unistr,str)
[/code]
有个库叫HTML Entities for Ruby(http://htmlentities.rubyforge.org/)
1.[code="java"]gem install htmlentities[/code]
2.
[code="java"]require 'htmlentities'
coder = HTMLEntities.new
string = '帮助'
result=coder.decode(string) [/code]
3.windows下可能由于结果是utf8编码会结果会显示乱码
[code="java"]require'iconv'
def conv(str)
Iconv.iconv("GBK//IGNORE","UTF-8//IGNORE",str)
end
puts conv(result)[/code]
[code="java"]=>帮助[/code]