The GW-Scripting list is a discussion list for information regarding the development and use of Window-Eyes scripts. Any subscriber of the GW-Scripting list has the ability to post on-topic messages.
From:
Ron ParkerSubject:
Re: using the openTextFile method of fileSystemObjectDate:
Thu, Mar 18, 2010 2:08:12 pmOn 3/18/2010 1:37 PM, Chip Orange wrote:
It's not always 100% possible to tell, without knowing ahead of time,
what format the file is. But if it's got a byte order mark in it, you can.
You could open it as Unicode and see if the first character is &HFEFF.
If it is, it's almost certainly Unicode. If not, you can't really know,
but you can sort of guess. If it's less than &H0100, chances are good
that it's Unicode. Otherwise, unless you're likely to be dealing with a
lot of non-English text, you should probably try it as ASCII. What
Notepad does is more sophisiticated, naturally, but even Notepad gets it
wrong sometimes.
(This ignores the possibility of UTF-8. You can also detect UTF-8 if it
has a byte order mark, but then you still have to decode it.)
I'd like this to be able to work regardless of the type of encoding of the
file, does anyone have any suggestion as to how I can achieve this?
It's not always 100% possible to tell, without knowing ahead of time,
what format the file is. But if it's got a byte order mark in it, you can.
You could open it as Unicode and see if the first character is &HFEFF.
If it is, it's almost certainly Unicode. If not, you can't really know,
but you can sort of guess. If it's less than &H0100, chances are good
that it's Unicode. Otherwise, unless you're likely to be dealing with a
lot of non-English text, you should probably try it as ASCII. What
Notepad does is more sophisiticated, naturally, but even Notepad gets it
wrong sometimes.
(This ignores the possibility of UTF-8. You can also detect UTF-8 if it
has a byte order mark, but then you still have to decode it.)




