I think you might check for the BOM for Unicode text-file, but there's
no certain and universal way to determine text encoding. I haven't
seen any text editor that does this.
Hi
Thanks for the reply, I'm new to unicode in general.
- Can you have a file thats part unicode and part ascii or are they
one or the other?
- Once the file is read into c# is there anyway of checking the loaded
strings to see if their unicode?
- Anyone got some example code for checking the BOM?
I want to write a noddy program to read in a file that maybe ascii,
maybe unicode. If its unicode it will rewrite it
as ascii (fine so far) and tell you thats it did it. It could check
the file size which I guess should be halved
but I'm surprised theres no easier way of doing this?
A file is really just a sequence of bytes. How those bytes are
interpreted is up to the programs using the file. You could certainly
have a file which changed encoding half way through - it would just be
a pain to work with.
- Once the file is read into c# is there anyway of checking the loaded
strings to see if their unicode?
No, it doesn't work that way. All strings in .NET are stored as Unicode
internally. You could see whether all of the characters in the string
are part of the ASCII character set though.
- Anyone got some example code for checking the BOM?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.