Re: Opening a text file that may be ASCII *or* Unicode



Since I can't find any documentation about TriStateUseDefault, I
decided to open the file in ASCII; read the first two characters;
close the file; compare those characters to 255 & 254; if true, open
in Unicode, otherwise open in ASCII.


Const ForReading = 1
Const TriStateFalse_ASCII = 0, TriStateTrue_Unicode = -1

'strFileName points to a text file in ASCII or Unicode
Set oTextFile = Fso.OpenTextFile (strFileName, ForReading, _
False,TriStateFalse_ASCII)

'read 1st 2 chrs, find Asc chr code
intAsc1Chr = Asc(oTextFile.Read(1))
intAsc2Chr = Asc(oTextFile.Read(1))

oTextFile.Close

If intAsc1Chr = 255 And intAsc2Chr = 254 Then

'open the file in Unicode
Set oTextFile = Fso.OpenTextFile (strFileName,ForReading, _
False,TriStateTrue_Unicode)

Else

'open the file in ASCII
Set oTextFile = Fso.OpenTextFile (strFileName,ForReading, _
False,TriStateFalse_ASCII)

End If


It's not elegant, but it seems to work.

regards, Andy
--
**********

Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com

To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org

**********
.



Relevant Pages

  • Re: Enhanced Unicode support for "Go" tools
    ... Right, you know ASCII? ... accent characters used in French and other European ... UNICODE isn't just about all the different alphabets out ... out wrongly because the character set the file was written in is ...
    (alt.lang.asm)
  • Re: ASCII Requires a Temporary Substitution During Encryption.
    ... ASCII has now been replaced by Unicode: ... makes ascii 00 and then the 94 standard characters ...
    (sci.crypt)
  • Re: Unicode Support
    ... > | single bit extra from ASCII for any ordinary ASCII characters... ... UNICODE character then check what "range" it's in with the table ... 7-bit ASCII characters are encoded in exactly the same way in UTF-8 ... All non-ASCII characters use a multi-byte sequence ...
    (alt.lang.asm)
  • Re: 128 bit password
    ... AdMod is ascii based, it doesn't write unicode. ... If I used the unicode version of ldap_mod it would likely be limited to 127 unicode characters. ... Joe Richards Microsoft MVP Windows Server Directory Services ...
    (microsoft.public.security)
  • Re: How to get the ascii code of Chinese characters?
    ... No. ASCII characters range is 0..127 while Unicode characters range is ... Actually, Unicode goes beyond 65535. ... non-"correct" representation is necessary anyway. ...
    (comp.lang.python)