国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > JS > 正文

Gb2312轉(zhuǎn)utf-8(vbs+js)

2024-05-06 16:54:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
 

昨天看了一下cocoon counter的代碼,發(fā)現(xiàn)里面是用vbScript轉(zhuǎn)的,費(fèi)了以上午時(shí)間來(lái)研究,還是被搞得暈糊糊- -

他的vb轉(zhuǎn)換函數(shù)是這樣的:


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()函數(shù)把10進(jìn)制的ANSI 字符代碼轉(zhuǎn)換成文字。文字本身應(yīng)該是unicode,也就是vbs自動(dòng)完成了gb-utf的轉(zhuǎn)換,下面是我測(cè)試的一些數(shù)據(jù):
測(cè)試代碼:(需要把上面的代碼加在前面)

<SCRIPT RUNAT=SERVER LANGUAGE=javascript>
Response.write("<br/>strx = chr(54992):");
Response.write(strx);
Response.write("<br/>strx.charCodeAt(0):");
Response.write(strx.charCodeAt(0));
Response.write("<br/>/"中/".charCodeAt(0):");
Response.write("中".charCodeAt(0));
Response.write("<br/>escape(strx):");
Response.write(escape(strx));
Response.write("<br/>encodeURI(strx):");
Response.write(encodeURI(strx));
Response.write("<br/>escape(/"中/"):");
Response.write(escape("中"));
Response.write("<br/>String.fromCharCode(20013):");
Response.write(String.fromCharCode(20013));
</SCRIPT>


分別調(diào)整文件存儲(chǔ)格式,codepage,charset得到的結(jié)果:

文件為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 錯(cuò)誤 'ASP 0245'
代碼頁(yè)值的混合使用
/referer_alapha/test2.asp,行 1
指定的 @CODEPAGE 值與包括文件的 CODEPAGE 或文件的保存格式的值不一致。


哈哈,是不是看暈了?我也暈,搞不明白為什么文件存儲(chǔ)的格式跟chr(54992)這個(gè)函數(shù)怎么會(huì)扯上關(guān)系,而String.fromCharCode(20013)可以得到正確結(jié)果(測(cè)試的第四部分?jǐn)?shù)據(jù))。大概是Vbs里面邏輯太混亂了。
不管怎樣,有了這個(gè)方法,gb2312轉(zhuǎn)utf-8簡(jiǎn)單多了。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平顺县| 麟游县| 奉化市| 汝州市| 休宁县| 三河市| 梨树县| 西吉县| 南川市| 和林格尔县| 霞浦县| 西和县| 阳春市| 乾安县| 华容县| 尚义县| 宾阳县| 庄河市| 台北县| 夏津县| 图木舒克市| 恭城| 武川县| 沁源县| 宾川县| 房山区| 麦盖提县| 酒泉市| 五指山市| 衡阳市| 锦州市| 溧阳市| 永嘉县| 五家渠市| 安岳县| 永年县| 图们市| 保靖县| 东阳市| 杂多县| 蕉岭县|