是否有任何方法可以在VBscript中将UTF-8转换为UTF-16 BE?
我有以下代码,但仅转换为UTF-16 LE。 我需要输出为UTF-16 BE。
parallel --halt now,fail=1 'cd {}; make {}' ::: t1 t2 t3
答案 0 :(得分:3)
Sub Utf8ToUtf16Le(fileIn,fileOut)
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Dim inputStream
Set inputStream = CreateObject("ADODB.Stream")
With inputStream
.Open
.Type = adTypeText
.Charset = "utf-8"
.LoadFromFile fileIn
.Position = 0
End With
With CreateObject("ADODB.Stream")
.Open
.Type = adTypeText
.Charset = "utf-16be"
.WriteText inputStream.ReadText
.Position = 0
.SaveToFile fileOut, adSaveCreateOverWrite
.Close
End With
inputStream.Close
End Sub
如果输出中需要BOM,我们可以使用
显式添加 .Charset = "utf-16be"
.WriteText ChrW(&hFEFF)
.WriteText inputStream.ReadText
或者,正如Kul-Tigin指出的那样,我们可以将.Charset
属性从utf-16be
更改为unicodeFEFF
。