欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

vb

當前位置:主頁 > 軟件編程 > vb >

vbs中將GB2312轉(zhuǎn)Unicode的代碼

來源:本站原創(chuàng)|時間:2020-01-10|欄目:vb|點擊: 次

今天寫了一個類似于下面的程序:

復制代碼 代碼如下:

Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo http.responseText

但是卻發(fā)現(xiàn)返回的中文都是亂碼,看了一下發(fā)現(xiàn)新浪的編碼竟然是gb2312的,汗,現(xiàn)在都是utf-8編碼的時代了。responseText對utf-8編碼支持得很好,但是如果是gb2312編碼就會返回亂碼,有時甚至會報錯。無奈,只好用responseBody然后自己轉(zhuǎn)碼。
復制代碼 代碼如下:

Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo GB2312ToUnicode(http.responseBody)

于是就要自己寫一個GB2312ToUnicode函數(shù),用ado很容易實現(xiàn):
復制代碼 代碼如下:

Function GB2312ToUnicode(str)
With CreateObject("adodb.stream")
.Type = 1 : .Open
.Write str : .Position = 0
.Type = 2 : .Charset = "gb2312"
GB2312ToUnicode = .ReadText : .Close
End With
End Function

這樣返回的就是VBS字符串默認的Unicode編碼了,不過用ado不能顯示我鬼使神差的VBS水平,于是自己根據(jù)“算法”再寫了一個:
復制代碼 代碼如下:

Function GB2312ToUnicode(str)
length = LenB(str) : out = ""
For i = 1 To length
c = AscB(MidB(str,i,1))
If c <= 127 Then
out = out & Chr(c)
Else
i = i + 1
d = Hex(AscB(MidB(str,i,1)))
c = "&H" & Hex(c) & d
out = out & Chr(c)
End If
Next
GB2312ToUnicode = out
End Function

只可惜效率太低,就當練練手吧。
原文:http://demon.tw/programming/vbs-gb2312-unicode.html

上一篇:用VBS設(shè)置靜態(tài)IP和DNS服務(wù)器地址的代碼

欄    目:vb

下一篇:獲取屏幕分辨率的VBS代碼

本文標題:vbs中將GB2312轉(zhuǎn)Unicode的代碼

本文地址:http://mengdiqiu.com.cn/a1/vb/7450.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有