StreamReader/Writer dealing with funny characters

Z

Zach

I am reading from an ASCII file containing addresses. Those addresses are
being combined with a letter to produce a mailing. So there is reading with
StreamReader (the address) and writing with StreamWriter (the address +
letter assembly).

Some of the addresses contain funnies like accents and what the Germans
would call Umlauts etc., etc.

I have tried

Encoding.UTF8
new UTFEncoding()
Encoding.ASCII

Neither of them do the job of properly dealing with the funnies.

Can someone help me out?

Many thanks,
Zach.
 
J

Jeff Johnson

I am reading from an ASCII file containing addresses. Those addresses are
being combined with a letter to produce a mailing. So there is reading with
StreamReader (the address) and writing with StreamWriter (the address +
letter assembly).

Some of the addresses contain funnies like accents and what the Germans
would call Umlauts etc., etc.

I have tried

Encoding.UTF8
new UTFEncoding()
Encoding.ASCII

Neither of them do the job of properly dealing with the funnies.

Nope, they wouldn't. Try Encoding.Default first. If that doesn't work then
you'll have to determine the code page that the file was created with, and
that probably won't be fun.
 
Z

Zach

Jeff Johnson said:
"Zach" <[email protected]> wrote in message
Nope, they wouldn't. Try Encoding.Default first. If that doesn't work then
you'll have to determine the code page that the file was created with, and
that probably won't be fun.
I had a brain wave, I read the file into Word, and saved it as text,
selecting the encoding. It worked.
Zach.
 
H

Harlan Messinger

Zach said:
I am reading from an ASCII file containing addresses. Those addresses
are being combined with a letter to produce a mailing. So there is
reading with StreamReader (the address) and writing with StreamWriter
(the address + letter assembly).

Some of the addresses contain funnies like accents and what the Germans
would call Umlauts etc., etc.

If the file contains accented characters, then it isn't an ASCII file.
You need to find out what the file's encoding *really* is.
I have tried

Encoding.UTF8
new UTFEncoding()
Encoding.ASCII

As I said, you need to know what the file's encoding is rather than
randomly trying things.
 
Z

Zach

As I said, you need to know what the file's encoding is rather than
randomly trying things.

Sorry, you didn't read my previous post? When you load a file to Word, Word
does the sorting out bit, subsequently you can select the encoding with
which to file the page in Word to a new file. That only takes a minute, and
isn't randomly trying things.

Zach.
 
H

Harlan Messinger

Zach said:
Sorry, you didn't read my previous post? When you load a file to Word,
Word does the sorting out bit, subsequently you can select the encoding
with which to file the page in Word to a new file. That only takes a
minute, and isn't randomly trying things.

It's not that I didn't see it. It's that I didn't realize that you would
consider the hack to be a satisfactory solution, or that as long as you
have something that "works", you are averse to acquiring a greater
understanding of the work you are doing.
 
Z

Zach

Harlan Messinger said:
It's not that I didn't see it. It's that I didn't realize that you would
consider the hack to be a satisfactory solution, or that as long as you
have something that "works", you are averse to acquiring a greater
understanding of the work you are doing.

If you had asked me whether I attempted to acquire greater
understanding about the issue, I would have have given you
an answer. What you did, assuming how I behaved, whilst not
knowing so, is called "projecting", don't do it, bad habit.
 
H

Harlan Messinger

Zach said:
If you had asked me whether I attempted to acquire greater
understanding about the issue, I would have have given you
an answer. What you did, assuming how I behaved, whilst not
knowing so, is called "projecting", don't do it, bad habit.

Wow--you're OUTSPOKEN about your lack of interest in genuinely
understanding what you are doing. Be sure to put that on your CV so
prospective employers will know what to expect.
 
A

Arne Vajhøj

If you had asked me whether I attempted to acquire greater
understanding about the issue, I would have have given you
an answer. What you did, assuming how I behaved, whilst not
knowing so, is called "projecting", don't do it, bad habit.

Ofcourse he assumed that you were interested in understanding.

If you are not then what you produce will be crap anyway, so there
would not be much point in trying to help you at all.

Arne
 
A

Arne Vajhøj

Sorry, you didn't read my previous post? When you load a file to Word,
Word does the sorting out bit, subsequently you can select the encoding
with which to file the page in Word to a new file. That only takes a
minute, and isn't randomly trying things.

Given that the same N bytes can more than one valid content
by assuming different encodings, then it is impossible
to detect encoding with 100% certainty.

If you need certainty, then you need to know the encoding.

If you can live with a guess then there are certain ways
of doing that.

Programmers tend to like to know.

Word users may be perfectly happy with 99% accuracy.

Arne
 
Z

Zach

Arne Vajhøj said:
Given that the same N bytes can more than one valid content
by assuming different encodings, then it is impossible
to detect encoding with 100% certainty.

If you need certainty, then you need to know the encoding.

If you can live with a guess then there are certain ways
of doing that.

Programmers tend to like to know.

Word users may be perfectly happy with 99% accuracy.

Arne
Thank you for your concern. The casus is described in the
opening post, q.v. During the weekend I needed to get the
job done and went for a quick fix. After the weekend with
everyone back at work I was abe to contact the company
from which I had purchased the addresses and receive
total certainty about te encoding.
Given that the same N bytes can more than one valid content
by assuming different encodings, then it is impossible
to detect encoding with 100% certainty.

Right. That was the problem.

Regards,
Zach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top