Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use VBS to realize batch gb2312 to utf-8

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you how to use VBS to achieve batch gb2312 to utf-8 content. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The code is as follows:

'/ * =

'* Intro drag all gb2312-encoded files to be converted to this file, and the program will automatically convert them to utf-8-encoded files

'* FileName GB2312.To.UTF-8.vbs

'* Author yongfa365

'* Version v1.0

'* WEB http://www.yongfa365.com

'* Email yongfa365 [at] qq.com

'* LastModify 2007-10-04 10:42:53

'* /

Set objArgs = WScript.Arguments

If objArgs.Count > 0 Then

If MsgBox ("this program only supports conversion from GB2312 to UTF-8" & vbCrLf& "if you drag a file in another format, please click" cancel ", vbOKCancel + vbExclamation + vbDefaultButton2," solemn reminder! ") = vbOK Then

For I = 0 To objArgs.Count-1

FileUrl = objArgs (I)

Call WriteToFile (FileUrl, ReadFile (FileUrl, "gb2312"), "utf-8")

Next

End If

Else

MsgBox "Please drag the" gb2312 files "you want to convert to this file" & vbCrLf& "the program will automatically convert them to utf-8 files", vbInformation, "Liu Yongfa warm Tip:"

End If

'

'function name: ReadFile

'function: use AdoDb.Stream objects to read text files in various formats

'

Function ReadFile (FileUrl, CharSet)

Dim Str

Set stm = CreateObject ("Adodb.Stream")

Stm.Type = 2

Stm.mode = 3

Stm.charset = CharSet

Stm.Open

Stm.loadfromfile FileUrl

Str = stm.readtext

Stm.Close

Set stm = Nothing

ReadFile = Str

End Function

'

'function name: WriteToFile

'function: use AdoDb.Stream objects to write text files in various formats

'Parameter: relative path of FileUrl- file; content of Str- file; CharSet- encoding format (utf-8,gb2312.)

'

Function WriteToFile (FileUrl, Str, CharSet)

Set stm = CreateObject ("Adodb.Stream")

Stm.Type = 2

Stm.mode = 3

Stm.charset = CharSet

Stm.Open

Stm.WriteText Str

Stm.SaveToFile FileUrl, 2

Stm.flush

Stm.Close

Set stm = Nothing

End Function

Thank you for reading! On "how to use VBS to achieve batch gb2312 to utf-8" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report