There is surprisingly little information on the various encoding options for
reading a text file. I have what seems to be a very basic issue: I'm reading
a text file that includes Spanish characters such as "ñ". When I read the
file into a string, that character is missing. Encoding seems to be the
culprit. File writers SHOULD begin a file with the BOM (Byte Order Mark) to
let us know what encoding to read the file with, but most software doesn't
do this so we are left with BOMless files. So how can we reliably read these
files without knowing what encoding it was written with?
Through trial and error I have found that using UTF-7 picks up these Spanish
characters, along with the English.
Dim Reader As New StreamReader(fs, System.Text.Encoding.UTF7).
Since I am clueless on matters of encoding, my question is: am I safe using
UTF-7 if I only care about English and Spanish? What is the downside? I
won't be able to read Romanian? Japanese?
Is there a way to programatically find the correct encoding without the BOM?
Chip 3 5105
Chip wrote: There is surprisingly little information on the various encoding options for reading a text file. I have what seems to be a very basic issue: I'm reading a text file that includes Spanish characters such as "ñ". When I read the file into a string, that character is missing. Encoding seems to be the culprit. File writers SHOULD begin a file with the BOM (Byte Order Mark) to let us know what encoding to read the file with, but most software doesn't do this so we are left with BOMless files.
Remember that these are byte order marks, which are intended to be used
for identifying whether an encoding uses Big Endian or Little Endian
representation. The fact that some encodings can be identified by their
BOM is just a nice side effect.
So how can we reliably read these files without knowing what encoding it was written with?
Only through application specific meta data (like HTTP headers).
There's no grand universal scheme to tell a file's character encoding.
Through trial and error I have found that using UTF-7 picks up these Spanish characters, along with the English. Dim Reader As New StreamReader(fs, System.Text.Encoding.UTF7).
That's quite likely not what you want. Try Encoding.Default.
Since I am clueless on matters of encoding, my question is: am I safe using UTF-7 if I only care about English and Spanish? What is the downside? I won't be able to read Romanian? Japanese?
Depends on the input. UTF-7 is only (and rarely?) used for E-mail. I
guess the chance to find a true UTF-7 encoded file is pretty much zero.
Is there a way to programatically find the correct encoding without the BOM?
As I said, in general no. If the range of possible encodings is
limited, you may be able to create a proper detection algorithm, though.
Cheers,
-- http://www.joergjooss.de
mailto:ne********@joergjooss.de
If you only care about english and spanish,
you'll be safe using iso-8859-1.
Juan T. Llibre
ASP.NET MVP
============
"Chip" <ch**@intradata.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... There is surprisingly little information on the various encoding options for reading a text file. I have what seems to be a very basic issue: I'm reading a text file that includes Spanish characters such as "ñ". When I read the file into a string, that character is missing. Encoding seems to be the culprit. File writers SHOULD begin a file with the BOM (Byte Order Mark) to let us know what encoding to read the file with, but most software doesn't do this so we are left with BOMless files. So how can we reliably read these files without knowing what encoding it was written with?
Through trial and error I have found that using UTF-7 picks up these Spanish characters, along with the English. Dim Reader As New StreamReader(fs, System.Text.Encoding.UTF7).
Since I am clueless on matters of encoding, my question is: am I safe using UTF-7 if I only care about English and Spanish? What is the downside? I won't be able to read Romanian? Japanese?
Is there a way to programatically find the correct encoding without the BOM?
Chip
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Y |
last post by:
Hi. I am attempting to display some Spanish text on my web site using
HTML. However, the Spanish characters, such as the 'N' in Espana are
not being displayed correctly. The text in the HTML source...
|
by: Carolina |
last post by:
Hi!
I have this C# code in a Button_Click event procedure:
string FilePath = MapPath("diseño.doc");
Response.ContentType = "Application/msword";
Response.AppendHeader("content-disposition",...
|
by: leticia larrosa |
last post by:
Hi,
I try to read a file that have 8 bit character, but contain some
character
whose code is more than 128 (spanish character).
When I read this file using ASCII (Dim oRead As StreamReader =...
|
by: pramod |
last post by:
Hi
I am facing the problem while inserting the spanish characters in the
DB2 UDB v8.2 database. We are pulling the data from SQL server through
informatica and then pushing the same in the DB2...
|
by: pziggs |
last post by:
I have been working on a page in English, and today began tackling the Spanish version of the site. I'm curious because on the homepage (www.nuestracasa.com/esp/) it displays the spanish language...
|
by: Amy L. |
last post by:
I am at an absolute loss on what is going on here. I have a text file
with some Spanish writing. Some of the characters have accents. I have
not found anyway to read this text file and echo the...
|
by: Bart Kastermans |
last post by:
I have written a little program that takes as input a text file,
converts
it to a list with appropriate html coding (making it into a nice
table).
Finally I want to upload this list as a textfile...
|
by: =?Utf-8?B?TGVvbg==?= |
last post by:
Hi everybody.
I am using streamreader to show spanish .htm page on my website.
Unfortunately those spanish characters that have stresses on top (like: Ó,á,
....) do not show correctly. Is...
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= |
last post by:
Hi misters,
I have embedded file that contains SQL. I read the file and execute SQL, but
in my SQL SERVER it appears stranges characters:
wrong: Nueva Aplicaci?n
ok: Nueva Aplicación
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |