In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Xiaobian to share with you how to convert GB2312 to Unicode in vbs, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Today I wrote a program similar to the following:
The code is as follows:
Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo http.responseText
However, I found that the returned Chinese are all garbled codes. I looked at it and found that the code of Sina is gb2312. Khan, it is now the era of utf-8 code. responseText supports utf-8 encoding very well, but if it is gb2312 encoding, it will return garbled code, and sometimes even report errors. Helpless, I had to use responseBody and then transcode myself.
The code is as follows:
Dim http
Set http = CreateObject("msxml2.xmlhttp")
http.open "GET","http://www.sina.com.cn/",False
http.send
WScript.Echo GB2312ToUnicode(http.responseBody)
So you have to write your own GB2312ToUnicode function, which is easy to implement with ado:
The code is as follows:
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
This way, the default Unicode encoding of the VBS string is returned. However, ado cannot display my VBS level, so I wrote another one according to the "algorithm":
The copy code is as follows:
Function GB2312ToUnicode(str)
length = LenB(str) : out = ""
For i = 1 To length
c = AscB(MidB(str,i,1))
If c
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.