All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET网络编程中经常会用到的27个函数集_.net资料_编程技术
asp.net:将多次查询的数据填充到同一数据源_[Asp.Net教程]
ASP.NET备份恢复SqlServer数据库_[Asp.Net教程]
microsoft sql server (mssql)数据导入导出详解 (多图文档)_[SQL Server教程]
解决JSP开发Web程序中的中文问题_[PHP教程]
HTML网页制作基础教程(1):认识HTML_[Html教程]
VS2005中的WebSite和WebApplication有何区别_.net资料_编程技术
脚本实例:用,javascript,来操作字符串_JavaScript技术_编程技术
详细学习PHP的日期时间函数date()_php资料_编程技术
Gridview和DataList中截取标题字符长度_[Asp.Net教程]
Reading number is top 10 pictures
真正的国产-非模拍 贵在是真实2
这还能睡得着?
这只猪到底犯了什么错?
Extremely rare TianShan Mountains snow lotus2
Park waits to have her picture taken exposed
漂亮脸蛋魔鬼身材1
你是左脑型还是右脑型
LiXiang early youth photo
Is said to be a Chinese female artist fame explicit pictures before1
西游日记3
Download software ranking
jdk1.6 for windows
Tram sex maniac 2 (H) rar bag19
Tram sex maniac 2 (H) rar bag17
The Bermuda triangle2
Professional killers2 data package
WebService在.NET中的实战应用教学视频 → 第5集
塘西风月痕
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
VC++6.0培训教程
Boxer's Top ten classic battle4
delv published in(发表于) 2013/12/31 6:34:17 Edit(编辑)
Gb2312转utf-8(vbs+js)_JavaScript技术_编程技术

Gb2312转utf-8(vbs+js)_JavaScript技术_编程技术

Gb2312转utf-8(vbs+js)_JavaScript技术_编程技术-你的首页-uuhomepage.com

  昨天看了一下cocoon counter的代码,发现里面是用vbScript转的,费了以上午时间来研究,还是被搞得晕糊糊- -


  他的vb转换函数是这样的:


Function DeCodeAnsi(s)
Dim i, sTmp, sResult, sTmp1
sResult = ""
For i=1 To Len(s)
If Mid(s,i,1)="%" Then
sTmp = "&H" & Mid(s,i+1,2)
If isNumeric(sTmp) Then
If CInt(sTmp)=0 Then
i = i + 2
ElseIf CInt(sTmp)>0 And CInt(sTmp)<128 Then
sResult = sResult & Chr(sTmp)
i = i + 2
Else
If Mid(s,i+3,1)="%" Then
sTmp1 = "&H" & Mid(s,i+4,2)
If isNumeric(sTmp1) Then
sResult = sResult & Chr(CInt(sTmp)*16*16 + CInt(sTmp1))
i = i + 5
End If
Else
sResult = sResult & Chr(sTmp)
i = i + 2
End If
End If
Else
sResult = sResult & Mid(s,i,1)
End If
Else
sResult = sResult & Mid(s,i,1)
End If
Next
DeCodeAnsi = sResult
End Function


  也就是用chr()函数把10进制的ANSI 字符代码转换成文字。文字本身应该是unicode,也就是vbs自动完成了gb-utf的转换,下面是我测试的一些数据:测试代码:(需要把上面的代码加在前面)



分别调整文件存储格式,codepage,charset得到的结果:


文件为ansi格式:
codepage=936:
Response.Charset = "gb2312";
strx = chr(54992)
strx:中
strx.charCodeAt(0):20013
"中".charCodeAt(0):20013
escape(strx):%u4E2D
encodeURI(strx):%E4%B8%AD
escape("中"):%u4E2D
String.fromCharCode(20013):中


Response.Charset = "utf-8";
strx = chr(54992)
strx:֐
strx.charCodeAt(0):20013
"֐".charCodeAt(0):20013
escape(strx):%u4E2D
encodeURI(strx):%E4%B8%AD
escape("֐"):%u4E2D
String.fromCharCode(20013):֐


codepage=65001:
Response.Charset = "gb2312";
strx = chr(54992)
strx:涓
strx.charCodeAt(0):20013
"".charCodeAt(0):-1.#IND
escape(strx):%u4E2D
encodeURI(strx):%E4%B8%AD
escape(""):
String.fromCharCode(20013):涓


Response.Charset = "utf-8";
strx = chr(54992)
strx:㝤
strx.charCodeAt(0):14180
"".charCodeAt(0):-1.#IND
escape(strx):%u3764
encodeURI(strx):%E3%9D%A4
escape(""):
String.fromCharCode(20013):中


文件为utf-8格式:
codepage=65001:
Response.Charset = "gb2312";
strx = chr(54992)
strx:涓
strx.charCodeAt(0):20013
"涓?.charCodeAt(0):20013
escape(strx):%u4E2D
encodeURI(strx):%E4%B8%AD
escape("涓?):%u4E2D
String.fromCharCode(20013):涓


Response.Charset = "utf-8";
strx = chr(54992)
strx:中
strx.charCodeAt(0):20013
"中".charCodeAt(0):20013
escape(strx):%u4E2D
encodeURI(strx):%E4%B8%AD
escape("中"):%u4E2D
String.fromCharCode(20013):中


codepage=936:
Active Server Pages 错误 'ASP 0245'
代码页值的混合使用
/referer_alapha/test2.asp,行 1


指定的 @CODEPAGE 值与包括文件的 CODEPAGE 或文件的保存格式的值不一致。


  哈哈,是不是看晕了?我也晕,搞不明白为什么文件存储的格式跟chr(54992)这个函数怎么会扯上关系,而String.fromCharCode(20013)可以得到正确结果(测试的第四部分数据)。大概是Vbs里面逻辑太混乱了。


  不管怎样,有了这个方法,gb2312转utf-8简单多了。





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.