Thanks!...It works!... This is the code in RB:
Dim f As FolderItem
Dim s As BinaryStream
Dim Data(4) As Int8
f = GetOpenFolderItem( "" )
If f <> nil then
s = f.OpenAsBinaryFile( False )
Data(0) = s.ReadInt8()
Data(1) = s.ReadInt8()
Data(2) = s.ReadInt8()
Data(3) = s.ReadInt8()
If Bitwise.BitAnd( Data(0), &hef ) = &hef and Bitwise.BitAnd
( Data(1), &hbb ) = &hbb and Bitwise.BitAnd( Data(2), &hbf ) = &hbf then
msgbox "UTF-8"
elseif Bitwise.BitAnd( Data(0), &hff ) = &hff and Bitwise.BitAnd
( Data(1), &hfe ) = &hfe then
msgbox "ucs-2le, ucs-4le, and ucs-16le"
elseif Bitwise.BitAnd( Data(0), &hfe ) = &hfe and Bitwise.BitAnd
( Data(1), &hff ) = &hff then
msgbox "utf-16 and ucs-2"
elseif Bitwise.BitAnd( Data(0), &h00 ) = &h00 and Bitwise.BitAnd
( Data(1), &h00 ) = &h00 and Bitwise.BitAnd( Data(2), &hfe ) = &hfe
and Bitwise.BitAnd( Data(3), &hff ) = &hff then
msgbox "ucs-4"
else
msgbox "ASCII"
end if
end if
Actually I only care about UTF-16 and the code detects perfectly
UTF16 (as long as it contains BOM of course). I am sure the code
could be shorter.
Stan
Stan!
There is an article called "Detecting File Encodings in .NET" on
http://www.devhood.com/tutorials/tutorial_details.aspx?
tutorial_id=469.
The provided code is very short and straight forward - it should
translate into RBScript without any problems...
Best,
Marcel
On 21.05.2006, at 18:20, Stan Busk wrote:
Hi,
Is there a simple way to determine whether a file is UTF16
encoded? It turns out that if I don't define the encoding of a
UTF16 file as UTF16 before reading it, I can't work with its
contents. Right now I have a UTF16 file on my desktop BBEdit
detects as such. I just wonder how BBedit finds out. Any clue? Can
we detect that with RB as well?
Have tried the info at http://support.realsoftware.com/
listarchives/realbasic-nug/2003-12/msg01239.html with no results.
--
~/Stan
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>