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

首頁 > 開發 > 綜合 > 正文

Gb2312轉utf-8(vbs+js)

2024-07-21 02:25:14
字體:
來源:轉載
供稿:網友

昨天看了一下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的轉換,下面是我測試的一些數據:
測試代碼:(需要把上面的代碼加在前面)

<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>


分別調整文件存儲格式,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簡單多了。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭锦后旗| 崇阳县| 辉县市| 黄浦区| 宣化县| 大关县| 平度市| 师宗县| 中超| 绍兴县| 姜堰市| 钟祥市| 揭东县| 安龙县| 西平县| 怀远县| 海晏县| 洪雅县| 淮阳县| 赞皇县| 广汉市| 鄂托克旗| 蒲江县| 海安县| 江安县| 陕西省| 黔东| 松阳县| 铜鼓县| 新和县| 资讯 | 石柱| 林周县| 玉门市| 健康| 昭苏县| 西充县| 佳木斯市| 辛集市| 日土县| 奉节县|