我正在尝试将 UCS2-Little Endian 中现有文件的编码从 Visual Basic 更改为 Windows-1251。
我正在使用以下代码:
Sub convertFile()
t = AlterCharset("utf-16LE", "windows-1251")
iFileNum = FreeFile
Open sFullPath For Output As #iFileNum
Print #iFileNum, t
Close #iFileNum
End Sub
Private Function AlterCharset(FromChaset, ToCharset)
Dim Bytes
Bytes = StringToBytes(FromChaset)
AlterCharset = BytesToString(Bytes, ToCharset)
End Function
Function StringToBytes(Charset)
Dim Stream: Set Stream = CreateObject("ADODB.Stream")
Stream.Type = adTypeText
Stream.Charset = Charset
Stream.Open
Stream.LoadFromFile sFullPath
Stream.flush
Stream.Position = 0
Stream.Type = adTypeBinary
StringToBytes = Stream.Read
Stream.Close
Set Stream = Nothing
End Function
Private Function BytesToString(Bytes, Charset)
Dim Stream: Set Stream = CreateObject("ADODB.Stream")
Stream.Charset = Charset
Stream.Type = adTypeBinary
Stream.Open
Stream.Write Bytes
Stream.flush
Stream.Position = 0
Stream.Type = adTypeText
BytesToString = Stream.ReadText
Stream.Close
Set Stream = Nothing
结束功能
问题是我总是在文本的开头得到一些字节,我无法在记事本++中打开它
有人可以看看我的代码有什么问题吗?