MartyConnelly
martyconnelly at shaw.ca
Wed Feb 1 15:08:20 CST 2006
Brief explanation of WSH and unicode
http://blogs.msdn.com/ericlippert/archive/2004/02/11/71472.aspx
Are you sure your input file is really Unicode format?
and are you using an odd codepage or locale? And also some intrinsic vb
functions will convert to ANSI
and return ANSI strings from Unicode input. The ANSI being dependant on
the machine OS codepage
Look at file with a hex editor, the first 2 or 3 bytes of the file
will be an indicator of Unicode type, plus for most Western European
languages
in Unicode every second byte will be 00
UTF-8 - EF BB BF
UTF-16LE - FF FE
UTF-16BE - FE FF
If I run this rough vbs code testuni.vbs below , I could only get an
error similar to yours on this type of read
if the file with your german string is saved as ANSI.
Set oTS = fs.OpenTextFile(ascfile, 1, False, -1) 'where -1 stands for
open as UNICODE
testuni.vbs
Function getString(StringBin)
Dim intcount
getString = ""
For intcount = 1 To LenB(StringBin)
getString = getString & Chr(AscB(MidB(StringBin, intcount, 1)))
Next
msgbox getString
End Function
Dim fs, ascfile, txtString, file, docString, unicodedatastring,
stream, oTS
Const ForReading = 1, ForWriting = 2, ForAppending = 3, vbUniCode = 64
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
ascfile = "C:\Access files\Scriptingdemo\german ascii.txt"
Set fs = CreateObject("scripting.filesystemobject")
Set file = fs.GetFile(ascfile)
Set stream = file.OpenAsTextStream
Set docString = file.OpenAsTextStream(ForReading,
TristateUseDefault)
txtString = docString.ReadAll
'UnicodeDataString = StrConv(txtString,vbUniCode)
unicodedatastring = getString(txtString)
MsgBox ("Get String-" & unicodedatastring)
MsgBox ("txtstring-" & txtString)
Wscript.Echo "Get String-" & unicodedatastring
Wscript.Echo "txtstring-" & txtString
' MsgBox ("StrConv-" & StrConv(txtString, vbUniCode))
'StrConv("Text Here",vbFromUnicode) ' vbFromUnicode = 128
Set oTS = fs.OpenTextFile(ascfile, 1, False, -1) 'where -1
stands for open as UNICODE
txtString = oTS.ReadLine
unicodedatastring = getString(txtString)
MsgBox ("Get String-" & unicodedatastring)
MsgBox ("txtstring-" & txtString)
Wscript.Echo "Get String-" & unicodedatastring
Wscript.Echo "txtstring-" & txtString
' MsgBox ("StrConv-" & StrConv(txtString, vbUniCode))
'cscript //U "C:\Access files\Scriptingdemo\testuni.vbs"
Francisco Tapia wrote:
>I have a text file with unicode characters... when I open it up in notepad i
>can read these characters just fine, I am running a vbscript script over it
>and I noticed that when It feeds the string into a variable it just uses
>some other wierd characters instead example:
>
>
> Set docString = file.OpenAsTextStream(ForReading,
>TristateUseDefault)
> txtString = docString.ReadAll
>
>
>the result string is:
>Spindeloption liefert ein höheres Drehmoment im höheren
>
>but the source text document shows the following string
>
>Spindeloption liefert ein höheres Drehmoment im höheren
>
>This is being ran from a vbscript... anybody have any idea as to why?
>
>--
>-Francisco
>http://pcthis.blogspot.com |PC news with out the jargon!
>http://sqlthis.blogspot.com | Tsql and More...
>
>
>
--
Marty Connelly
Victoria, B.C.
Canada