PC Review


Reply
 
 
Alex Leduc
Guest
Posts: n/a
 
      25th Aug 2003
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:\\someFrenchFile.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.Default 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 programmatically decide what Locale to use with all ASCII strings?

Alexandre Leduc

 
Reply With Quote
 
 
 
 
Dave Quigley[work]
Guest
Posts: n/a
 
      25th Aug 2003
Your stream reader is missing something important for the second parameter
use System.Text.Encoding.ASCII
otherwise it should eb unicode i believe.

This should helo you

"Alex Leduc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:\\someFrenchFile.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.Default 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 programmatically decide what Locale to use with all ASCII strings?
>
> Alexandre Leduc
>



 
Reply With Quote
 
Jack Hanebach
Guest
Posts: n/a
 
      25th Aug 2003
"Alex Leduc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 programmatically 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...)


 
Reply With Quote
 
Jon Skeet
Guest
Posts: n/a
 
      25th Aug 2003
Alex Leduc <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
Alex Leduc
Guest
Posts: n/a
 
      25th Aug 2003
Dave Quigley[work] wrote:
> Your stream reader is missing something important for the second parameter
> use System.Text.Encoding.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.

 
Reply With Quote
 
Alex Leduc
Guest
Posts: n/a
 
      25th Aug 2003
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.

 
Reply With Quote
 
Michael A. Covington
Guest
Posts: n/a
 
      26th Aug 2003

"Alex Leduc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Anthony Christianson
Guest
Posts: n/a
 
      26th Aug 2003
Try:

StreamReader sr = new StreamReader("C:\\someFrenchFile.txt",
System.Text.Encoding.GetEncoding("ISO-8859-1") );
string strInput = sr.ReadToEnd();



"Alex Leduc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Marc Scheuner [MVP ADSI]
Guest
Posts: n/a
 
      26th Aug 2003
>> Your stream reader is missing something important for the second parameter
>> use System.Text.Encoding.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.Encoding.Default. Works
for German umlauts for me :-)

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Reply With Quote
 
Alex Leduc
Guest
Posts: n/a
 
      26th Aug 2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
merging ascii files GBA Microsoft Access VBA Modules 4 25th Mar 2009 09:09 PM
ASCII files domineaux Microsoft Access 1 20th Mar 2008 03:50 AM
ASCII files ...please help riggi Microsoft Excel Misc 5 27th Jun 2006 04:25 AM
Re: Saving ASCII files Cindy M -WordMVP- Microsoft Word Document Management 0 21st Sep 2004 10:29 AM
ASCII files Alex Leduc Microsoft C# .NET 14 30th Aug 2003 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 AM.