I think I overlook something, but when a write to a text file using a
StreamWriter, the file is written as unicode. I'm writing information that is
retrieve from nvarchar fields on SQL server. I have a problem with characters
like Ã?, Ã?, etc. When looking at the file they seems to be correct, but in
some applications the characters are shown as Ã?Å? or Ã?â??. How can I write
single byte characters to the file? Just specifying new
StreamWriter(FileName, false, Encoding.ASCII) doesn't solve the problem,
because the characters are completely wrong. Please advise.

Thanks in advance.

Re: How to write plain ascii to a textfile by Lionel

Lionel
Fri Jan 28 10:00:11 CST 2005


Use Encoding.Default to use the current ANSI code page of your computer:

StreamWriter OutFile = new StreamWriter("c:\\temp\\filename.txt",
Encoding.Default).

Lionel.


"Edward" <Edward@discussions.microsoft.com> a écrit dans le message de news:
74238EA5-B225-4984-BBBF-D377442FF883@microsoft.com...
>I think I overlook something, but when a write to a text file using a
> StreamWriter, the file is written as unicode. I'm writing information that
> is
> retrieve from nvarchar fields on SQL server. I have a problem with
> characters
> like Ü, Ö, etc. When looking at the file they seems to be correct, but in
> some applications the characters are shown as Ão or Ã-. How can I write
> single byte characters to the file? Just specifying new
> StreamWriter(FileName, false, Encoding.ASCII) doesn't solve the problem,
> because the characters are completely wrong. Please advise.
>
> Thanks in advance.



RE: How to write plain ascii to a textfile by PIEBALD

PIEBALD
Fri Jan 28 10:09:02 CST 2005

Well are you trying to write unicode or ASCII? You say you want to write
ASCII but have non-ASCII characters handled properly?

Anyway, it sounds more like the problem is on the other end, that the "some
applications" are not handling the data correctly. If they require ASCII,
then stop trying to send them non-ASCII characters.

Re: How to write plain ascii to a textfile by Jon

Jon
Fri Jan 28 11:34:37 CST 2005

Edward <Edward@discussions.microsoft.com> wrote:
> I think I overlook something, but when a write to a text file using a
> StreamWriter, the file is written as unicode.

By default it's written as UTF-8.

> I'm writing information that is
> retrieve from nvarchar fields on SQL server. I have a problem with characters
> like ?, ?, etc. When looking at the file they seems to be correct, but in
> some applications the characters are shown as ?? or ??. How can I write
> single byte characters to the file? Just specifying new
> StreamWriter(FileName, false, Encoding.ASCII) doesn't solve the problem,
> because the characters are completely wrong. Please advise.

I assume those question marks are meant to have non-ASCII characters -
eg accented characters. Note that ASCII doesn't have any accents - what
people often think of as "extended ASCII" is a variety of 8-bit
character sets which are compatible with ASCII for the first 128
values.

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

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: How to write plain ascii to a textfile by Naveen

Naveen
Fri Jan 28 15:07:53 CST 2005

All the stream wrier and reader classes use UTF8 encoding for text input and
output. If your source string is unicode or mutibyte, then it is going to
read it as multibyte. You will have to change the encoding of the writer.


"Edward" <Edward@discussions.microsoft.com> wrote in message
news:74238EA5-B225-4984-BBBF-D377442FF883@microsoft.com...
>I think I overlook something, but when a write to a text file using a
> StreamWriter, the file is written as unicode. I'm writing information that
> is
> retrieve from nvarchar fields on SQL server. I have a problem with
> characters
> like Ü, Ö, etc. When looking at the file they seems to be correct, but in
> some applications the characters are shown as Ão or Ã-. How can I write
> single byte characters to the file? Just specifying new
> StreamWriter(FileName, false, Encoding.ASCII) doesn't solve the problem,
> because the characters are completely wrong. Please advise.
>
> Thanks in advance.



Re: How to write plain ascii to a textfile by Edward

Edward
Sat Jan 29 08:45:02 CST 2005

Thanks,

I knew it was UTF-8 and noticed that indeed the accented characters were
written as double byte. How can I write it as a single byte? For example the
capital A with two dots above converted to ascii-code 142.


"Jon Skeet [C# MVP]" wrote:

> Edward <Edward@discussions.microsoft.com> wrote:
> > I think I overlook something, but when a write to a text file using a
> > StreamWriter, the file is written as unicode.
>
> By default it's written as UTF-8.
>
> > I'm writing information that is
> > retrieve from nvarchar fields on SQL server. I have a problem with characters
> > like ?, ?, etc. When looking at the file they seems to be correct, but in
> > some applications the characters are shown as ?? or ??. How can I write
> > single byte characters to the file? Just specifying new
> > StreamWriter(FileName, false, Encoding.ASCII) doesn't solve the problem,
> > because the characters are completely wrong. Please advise.
>
> I assume those question marks are meant to have non-ASCII characters -
> eg accented characters. Note that ASCII doesn't have any accents - what
> people often think of as "extended ASCII" is a variety of 8-bit
> character sets which are compatible with ASCII for the first 128
> values.
>
> See http://www.pobox.com/~skeet/csharp/unicode.html
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
>

Re: How to write plain ascii to a textfile by Jon

Jon
Sat Jan 29 09:14:34 CST 2005

Edward <Edward@discussions.microsoft.com> wrote:
> I knew it was UTF-8 and noticed that indeed the accented characters were
> written as double byte. How can I write it as a single byte? For example the
> capital A with two dots above converted to ascii-code 142.

There's no such thing as ascii-code 142. ASCII only goes as far as 127
(or 126, depending on how you count it). I suspect you mean either
ISO-8859-1 or Windows Code Page 1252. Please read the page I linked to
before (http://www.pobox.com/~skeet/csharp/unicode.html) which has more
information about the encodings and how to use them from .NET.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: How to write plain ascii to a textfile by Michael

Michael
Tue Feb 01 07:21:11 CST 2005


"Lionel LASKE" <llaske@c2s.fr> wrote in message
news:%23ycb0JVBFHA.3376@TK2MSFTNGP12.phx.gbl...
>
> Use Encoding.Default to use the current ANSI code page of your computer:
>
> StreamWriter OutFile = new StreamWriter("c:\\temp\\filename.txt",
> Encoding.Default).
>
> Lionel.

Edward, it really is as simple as this... =)

- Michael S