473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how find if a file is unicode or not

Hi
As the subject says, how do you know if a file is unicode, ascii or
whatever

ta
Jun 27 '08 #1
4 8172
On Jun 25, 5:15 pm, codefragm...@googlemail.com wrote:
As the subject says, how do you know if a file is unicode, ascii or
whatever
You can't find out for sure. You can read some portion of it and check
for common patterns, but it's still only going to be a guess.

Is there no way that you can require files to be in a certain encoding
in your situation?

Jon
Jun 27 '08 #2
On Jun 26, 1:15*am, codefragm...@googlemail.com wrote:
Hi
* As the subject says, how do you know if a file is unicode, ascii or
whatever

ta
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.

Jun 27 '08 #3
On 25 Jun, 17:20, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 25, 5:15 pm, codefragm...@googlemail.com wrote:
* As the subject says, how do you know if a file is unicode, ascii or
whatever

You can't find out for sure. You can read some portion of it and check
for common patterns, but it's still only going to be a guess.

Is there no way that you can require files to be in a certain encoding
in your situation?

Jon
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?
Jun 27 '08 #4
<co**********@googlemail.comwrote:
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?
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?
Not offhand - although I believe StreamReader has an overload to auto-
detect the BOM. Have a look at the docs to check.

See http://pobox.com/~skeet/csharp/unicode.html for an introduction to
the topic.
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
4
by: Guilherme Salgado | last post by:
Hi there, I have a python source file encoded in unicode(utf-8) with some iso8859-1 strings. I've encoded this file as utf-8 in the hope that python will understand these strings as unicode...
19
by: Svennglenn | last post by:
I'm working on a program that is supposed to save different information to text files. Because the program is in swedish i have to use unicode text for ÅÄÖ letters. When I run the following...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
5
by: Jamie | last post by:
I have a file that was written using Java and the file has unicode strings. What is the best way to deal with these in C? The file definition reads: Data Field Description CHAR File...
2
by: hezhenjie | last post by:
Hi, all: I just need to parse a unicode file, and assume to get data one line by one line. I use _wfopen(), fgetws(), wcslen(), wcsstr(), making it work normally on Windows platform. However,...
4
by: Arif | last post by:
My programs searches the header of input barcode in index file. Get the record position next to Barcode header. Then moves the file pointer of products file to reach that record. My products...
6
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.