none
VBS - how to hard code utf8 or unicode ucs2 strings? RRS feed

  • Question

  • Hi,

    I want to dump data into an utf8 text file, if I read the input from an Inputbox or an utf8 file, no problem.

    But how do I hard code a non ascii string within a vbs script (utf8 encoded)?

    Working code:

    Dim objStream
    Set objStream = CreateObject("ADODB.Stream")
    objStream.CharSet = "utf-8"
    objStream.Open
    ucs2String = InputBox( "Type some non-ascii characters:")
    objStream.WriteText ucs2String
    Set objFSO=CreateObject("Scripting.FileSystemObject")
    currentWorkingDir = objFSO.GetAbsolutePathName(".")
    oFileName = currentWorkingDir & "\test vbs uft8 encoding.txt"
    objStream.SaveToFile oFileName, 1
    If in the input box I type for instance: ↷¼½¾ GREEK αβγδεζη

    It's OK.

    But how to replace the InputBox code by something as:

    ucs2String = "↷¼½¾ GREEK αβγδεζη"

    Thanks

    P.S. OS Win 7 64bits

    Tuesday, October 27, 2015 3:30 PM

Answers

  • When I save your script as Unicode then the interpreter runs it without complaining and it generates the expected output.
    Tuesday, October 27, 2015 4:44 PM

All replies

  • VBScript does not support double byte characters.  Use PowerShell instead.


    \_(ツ)_/

    Tuesday, October 27, 2015 3:33 PM
  • But how to replace the InputBox code by something as:
    ucs2String = "↷¼½¾ GREEK αβγδεζη"

    I have no problem when using your characters in an input box.

    x = InputBox("↷¼½¾ GREEK αβγδεζη", "My Input Box")


    Tuesday, October 27, 2015 4:07 PM
  • x = InputBox("↷¼½¾ GREEK αβγδεζη", "My Input Box","↷¼½¾ GREEK αβγδεζη")


    \_(ツ)_/

    Tuesday, October 27, 2015 4:36 PM
  • When I save your script as Unicode then the interpreter runs it without complaining and it generates the expected output.
    Tuesday, October 27, 2015 4:44 PM
  • VBScript only understand ansi and Unicode.  You cannot use UTF-8 or any other encoding.


    \_(ツ)_/

    Tuesday, October 27, 2015 5:03 PM
  • VBScript only understand ansi and Unicode.  You cannot use UTF-8 or any other encoding.


    \_(ツ)_/


    I did write "Unicode" in my previous reply and the script did run, producing the characters that the OP specified. I do not know why you mention UTF.
    Tuesday, October 27, 2015 6:21 PM
  • VBScript only understand ansi and Unicode.  You cannot use UTF-8 or any other encoding.


    \_(ツ)_/


    I did write "Unicode" in my previous reply and the script did run, producing the characters that the OP specified. I do not know why you mention UTF.

    The OP asked for UTF-8.  I was posting a response to his request.


    \_(ツ)_/

    Tuesday, October 27, 2015 6:32 PM
  • The OP asked for UTF-8.  I was posting a response to his request.


    \_(ツ)_/


    The OP asked for UTF8 or Unicode. Unicode seems to do the trick.
    Tuesday, October 27, 2015 6:39 PM