473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASCII files

I'm trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use.

So If I have machine who's default Locale is "en-US" and I open some
french text like this:

[C# exaple that has the same behaviour in any .net languages]

StreamReader sr = new StreamReader("C :\\someFrenchFi le.txt");
string strInput = sr.ReadToEnd();

Suppose the file contains this:
"Le Québec en été."
the characters that I get in strInput are:
"Le Qu?bec en ?t?."

If I change the default Locale in the Control Panel and use
Encoding.Defaul t in the StreamReader's constructor parameters, I get the
right characters in strInput:
"Le Québec en été."

What I'd like to be able to do is load the french string with the right
characters regardless of what's the machine's default Locale. What's the
way to programmaticall y decide what Locale to use with all ASCII strings?

Alexandre Leduc

Nov 15 '05 #1
14 1945
Your stream reader is missing something important for the second parameter
use System.Text.Enc oding.ASCII
otherwise it should eb unicode i believe.

This should helo you

"Alex Leduc" <le******@netsc ape.net> wrote in message
news:eO******** ******@TK2MSFTN GP09.phx.gbl...
I'm trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use.

So If I have machine who's default Locale is "en-US" and I open some
french text like this:

[C# exaple that has the same behaviour in any .net languages]

StreamReader sr = new StreamReader("C :\\someFrenchFi le.txt");
string strInput = sr.ReadToEnd();

Suppose the file contains this:
"Le Québec en été."
the characters that I get in strInput are:
"Le Qu?bec en ?t?."

If I change the default Locale in the Control Panel and use
Encoding.Defaul t in the StreamReader's constructor parameters, I get the
right characters in strInput:
"Le Québec en été."

What I'd like to be able to do is load the french string with the right
characters regardless of what's the machine's default Locale. What's the
way to programmaticall y decide what Locale to use with all ASCII strings?

Alexandre Leduc

Nov 15 '05 #2
"Alex Leduc" <le******@netsc ape.net> wrote in message
news:eO******** ******@TK2MSFTN GP09.phx.gbl...
I'm trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use. [snip] What I'd like to be able to do is load the french string with the right
characters regardless of what's the machine's default Locale. What's the
way to programmaticall y decide what Locale to use with all ASCII strings?


If you know what's the code page of the file you can try to set
StreamReader's CurrentEncoding property to ASCIIEncoding with the CodePage
set to file's code page. [Warning! haven't tried it myself :)]

OTOH if you want to read arbitrary file in arbitrary language I'm afraid
it's not possible... (or, at least, I don't know the way...)
Nov 15 '05 #3
Alex Leduc <le******@netsc ape.net> wrote:
I'm trying to load ASCII files that contain characters from the French
language


Assuming you mean accented characters, that's impossible. ASCII doesn't
contain any accented characters.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #4
Dave Quigley[work] wrote:
Your stream reader is missing something important for the second parameter
use System.Text.Enc oding.ASCII
otherwise it should eb unicode i believe.


I forgot to mention that I've tried that and the result I get is:

"Le Qubec en t."

It removes all accentuated characters from the string.

Nov 15 '05 #5
Bruno Jouhier [MVP] wrote:
ASCII is a 7-bit codeset and it does not cover accentuated characters.

What you want is probably ISO-Latin1 also known as ISO-8859-1, which
contains the French accentuated characters. So, you should specify this
encoding when you open the StreamReader.

Bruno.


Could you tell me how to do that in code? I find the SDK documentation
on this topic to be a bit confusing.

Nov 15 '05 #6

"Alex Leduc" <le******@netsc ape.net> wrote in message
news:eO******** ******@TK2MSFTN GP09.phx.gbl...
I'm trying to load ASCII files that contain characters from the French
language in a way that is independant of whatever Locale the machine is
configured to use.


If it contains anything non-English (such as accented letters), it's not
ASCII.

What you have is some kind of extension of ASCII, and there are many such.
Nov 15 '05 #7
Try:

StreamReader sr = new StreamReader("C :\\someFrenchFi le.txt",
System.Text.Enc oding.GetEncodi ng("ISO-8859-1") );
string strInput = sr.ReadToEnd();

"Alex Leduc" <le******@netsc ape.net> wrote in message
news:O1******** ******@TK2MSFTN GP09.phx.gbl...
Bruno Jouhier [MVP] wrote:
ASCII is a 7-bit codeset and it does not cover accentuated characters.

What you want is probably ISO-Latin1 also known as ISO-8859-1, which
contains the French accentuated characters. So, you should specify this
encoding when you open the StreamReader.

Bruno.


Could you tell me how to do that in code? I find the SDK documentation
on this topic to be a bit confusing.

Nov 15 '05 #8
>> Your stream reader is missing something important for the second parameter
use System.Text.Enc oding.ASCII
otherwise it should eb unicode i believe.


I forgot to mention that I've tried that and the result I get is:
"Le Qubec en t."
It removes all accentuated characters from the string.


Is it really ASCII (as in DOS / OEM), or is it ANSI (as in a regular
Windows file)??

If it's ANSI / Windows, try using System.Text.Enc oding.Default. Works
for German umlauts for me :-)

Marc

=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)i nova.ch
Nov 15 '05 #9
Yeah I think what I was talking about is ANSI. I never understood the
difference between the two so I assumed they were two different names
for the same thing.

Nov 15 '05 #10

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

Similar topics

11
9035
by: Sebastian Krause | last post by:
Hello, I tried to read in some large ascii files (200MB-2GB) in Python using scipy.io.read_array, but it did not work as I expected. The whole idea was to find a fast Python routine to read in arbitrary ascii files, to replace Yorick (which I use right now and which is really fast, but not as general as Python). The problem with scipy.io.read_array was, that it is really slow, returns errors when trying to process large files and it...
8
23647
by: W. de Jonge | last post by:
Who can help me? I want to create a link(href) which opens an .doc or an ..xls directly in MS Word or MS Excell and not in IE so that I don't have to save the document first en open it from Explorer. I asked our webmaster at the office but he didn't know the answer so I hope you can help me. Greetz Willem
3
1982
by: Mark | last post by:
I'm working with ASCII data files provided by data vendors in a standard format. These files contains lots of various pieces of information for each reporting entity in the file. Currently I have code to read these ASCII files and arrange the data into a managable table structure. There is a key field unique to each entity called PROPNUM. The workflow is such that one ASCII file (file1.txt) is loaded into this system. I have a data...
16
2743
by: chunhui_true | last post by:
I know in ASCII '\r' is 0x0d,'\n' is 0x0a. But some say ASCII characters in UTF8 is unchanged. Now I want to know in UTF8 '\r' and '\n' are already 0x0d and 0x0a?? Could anybody can tell me? Very Thanks!!!!
4
3852
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII characters"(No. 128 to 255) . e.g., in one version No. 224 is the symbol alpha, in another, it's a "a" with a ` on it... How come? You can see it here: http://www.kturby.com/cables/ascii2.htm
18
34148
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found Encoding.Convert, but that needs byte arrays. Thanks, /Ger
12
1987
by: IamIan | last post by:
I searched the archives but couldn't find anyone else with this problem. Basically I'm grabbing all ASCII files in a directory and doing geoprocessing on them. I need to calculate a z-factor based on the latitude of the ASCII file being worked on, which is in the filename. If I type in the code manually it works and reads the latitude value from the ASCII filename, but when run within ArcGIS it crashes when it gets to int(LatString)....
18
9084
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a database. The files are written by a late 1980's PC Pascal programme, for which I don't have the source code. I've managed to reverse engineer the file format. The strings are stored as Ascii in the file, with the first byte indicating the string...
12
9141
by: bg_ie | last post by:
Hi, I'm updating my program to Python 2.5, but I keep running into encoding problems. I have no ecodings defined at the start of any of my scripts. What I'd like to do is scan a directory and list all the files in it that contain a non ascii character. How would I go about doing this? Thanks,
399
12947
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
0
9663
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9979
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.