Unicode到UTF-8 [英] Unicode to UTF-8
问题描述
我使用vbscript从db2中提取数据并写入文件。
写入文件如:
i'm using vbscript to extract data from db2 and write to file. Writing to file like:
Set objTextFile = objFSO.CreateTextFile(sFilePath, True, True)
在unicode中创建文件。但是这是xml文件,它使用UTF-8。
所以当我打开xml文件与MS XML记事本它抛出的错误:
'十六进制值0x00是一个无效字符'
that creates file in unicode. But that is xml file and it uses UTF-8. So when i open xml file with MS XML Notepad it throws error: 'hexadecimal value 0x00 is an invalid character'
文本文件与TextPad并保存为UTF-8。之后,XML打开没有任何问题。
可以通过vbScript将文件从Unicode转换为UTF-8?
So i opening this text file with TextPad and saving in UTF-8. After that XML opens without any problems. Can i convert file from Unicode to UTF-8 by vbScript?
推荐答案
使用Stream对象保存文件与utf-8字符集可能会更好地为您工作;这里有一个简单的.vbs函数可以测试你的数据:
Using the Stream object to save your file with the utf-8 charset might work better for you; here's a simple .vbs function you could test out on your data:
Option Explicit
Sub Save2File (sText, sFile)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
With oStream
.Open
.CharSet = "utf-8"
.WriteText sText
.SaveToFile sFile, 2
End With
Set oStream = Nothing
End Sub
' Example usage: '
Save2File "The data I want in utf-8", "c:\test.txt"
这篇关于Unicode到UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!