gpt4 book ai didi

macros - 如何将文本文件的编码格式从 Unicode 更改为 UTF-8

转载 作者:行者123 更新时间:2023-12-02 05:40:40 24 4
gpt4 key购买 nike

Dim txtFile, fileObj, streamObj, s

Set txtFile = CreateObject(fileName)

Set streamObj = CreatreObject("adodb.Stream")
streamObj.Charset = "UTF-8"
streamObj.open
Set fileObj = txtFile.OpenTextFile("filePath")

Do Until fileObj.AtEndOfStream
s = fileObj.ReadLine
txtObj.WriteText s
Loop

txtObj.SaveToFile "D:\A4\Message_tool\surya.msg", 2
fileObj.Close

执行此代码后,surya.msg 的编码格式是“ANSCII”,但我希望它是“UTF-8”

最佳答案

Const adTypeText = 2
Const adSaveCreateOverWrite = 2

Dim inputFile, outputFile
inputFile = "input_file.txt"
outputFile = "output_file.txt"

Dim inputStream
Set inputStream = WScript.CreateObject("adodb.stream")
With inputStream
.Type = adTypeText
.Charset = "unicode"
.Open
.LoadFromFile inputFile
End With

Dim outputStream
Set outputStream = WScript.CreateObject("adodb.stream")
With outputStream
.Type = adTypeText
.Charset = "utf-8"
.Open
.WriteText inputStream.ReadText
.SaveToFile outputFile, adSaveCreateOverWrite
End With

inputStream.Close
outputStream.Close

关于macros - 如何将文本文件的编码格式从 Unicode 更改为 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25684660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com