Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode to UTF-8

i'm using vbscript to extract data from db2 and write to file. Writing to file like:

Set objTextFile = objFSO.CreateTextFile(sFilePath, True, True)

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'

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?

like image 674
Ruslan Avatar asked Nov 08 '10 16:11

Ruslan


People also ask

How do I encode Unicode to UTF-8?

Base Convert Unicode symbols to UTF-8 in this base. Set the byte delimiter character here. Add a Prefix Use prefix "0b" for binary, prefix "o" for octal, and prefix "0x" for hex values. Add Padding Add zero padding to small values to make them all the same length.

Is UTF-8 the same as Unicode?

The Difference Between Unicode and UTF-8 Unicode is a character set. UTF-8 is encoding. Unicode is a list of characters with unique decimal numbers (code points).

What are UTF-8 codes?

UTF-8 is a “variable-width” encoding standard. This means that it encodes each code point with a different number of bytes, between one and four. As a space-saving measure, commonly used code points are represented with fewer bytes than infrequently appearing code points.


1 Answers

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"
like image 141
stealthyninja Avatar answered Nov 03 '22 03:11

stealthyninja