1

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

終了機能

問題は、テキストの先頭に常に数バイトが表示され、メモ帳++で開くことができないことです

誰かが見て、私のコードで何が間違っている可能性があるかを見てもらえますか?

4

1 に答える 1