File IO loses some characters

T

Todd

I am writing a method to do some standard conversions on the text of a
file. However, I am having difficulty getting the StreamReader and
StreamWriter to behave. The input file is a Visual Studio 6.0 C++ .rc
file (I believe it's in ASCII). The input file contains a line with a
copyright character. I am unable to read and write the file without
the file IO routines messing up the copyright character. The code is
similar to the following:

String text = String.Empty;
using (TextReader reader = new StreamReader(file.FullName,
System.Text.Encoding.UTF7))
{
text = reader.ReadToEnd();
}
using (TextWriter writer = new StreamWriter(file.FullName, false,
System.Text.Encoding.UTF7))
{
writer.Write(transformedText);
}

I have tried every combination of encoding for both the reader and the
writer with no luck.

Every encoding except UTF7 fails to retrieve the copyright symbol on
the read. However every encoding I try for the write fails. The worst
is UTF7. The best is UTF8 or ASCII. However, in both cases the file
is unreadable by Visual Studio 6.0.

Any ideas?

Todd Breyman
 
J

Jon Skeet [C# MVP]

Todd said:
I am writing a method to do some standard conversions on the text of a
file. However, I am having difficulty getting the StreamReader and
StreamWriter to behave. The input file is a Visual Studio 6.0 C++ .rc
file (I believe it's in ASCII). The input file contains a line with a
copyright character.

In that case it can't be ASCII - ASCII doesn't contain a copyright
character.

I suggest you try Encoding.Default, or Encoding.GetEncoding (28591)
(which is ISO-8859-1).
 
T

Todd

Excellent. Modifying the write statement to use Encoding.Default
worked perfectly. Thanks.

Todd Breyman
 
O

Olaf Baeyens

I am writing a method to do some standard conversions on the text of a
In that case it can't be ASCII - ASCII doesn't contain a copyright
character.
ASCII is from DOS, Windows 16 bit started with ANSI.
Now we have tons of different formats.
 
O

Olaf Baeyens

ASCII is from DOS, Windows 16 bit started with ANSI.
What DOS definitly not MS-DOS it existed already very long before that was
made, starting at 1963.
You are perfectly right. :)
 
M

Michael A. Covington

Olaf Baeyens said:
ASCII is from DOS, Windows 16 bit started with ANSI.
Now we have tons of different formats.

Worse than that. ASCII is from teletype machines. DOS added 128 more
characters to it. ANSI (with Windows) added a different 128.
 
J

Jon Skeet [C# MVP]

Michael A. Covington said:
Worse than that. ASCII is from teletype machines. DOS added 128 more
characters to it. ANSI (with Windows) added a different 128.

Even with DOS there were several different code pages, for different
regions.
 
M

Michael A. Covington

Jon Skeet said:
Even with DOS there were several different code pages, for different
regions.

Late versions of DOS, yes.

I should have said that it was the IBM PC hardware, not DOS, that introduced
the first 8-bit PC character set.
 

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