473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File IO loses some characters

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

Nov 22 '05 #1
8 1279
Todd <To**********@sungard.com> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Excellent. Modifying the write statement to use Encoding.Default
worked perfectly. Thanks.

Todd Breyman

Nov 22 '05 #3
> > 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.

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

--
http://www.skyscan.be
Nov 22 '05 #4
Olaf,
ASCII is from DOS, Windows 16 bit started with ANSI.
Now we have tons of different formats.

What DOS definitly not MS-DOS it existed already very long before that was
made, starting at 1963.

http://en.wikipedia.org/wiki/Ascii
Cor
Nov 22 '05 #5
> > ASCII is from DOS, Windows 16 bit started with ANSI.
Now we have tons of different formats.

What DOS definitly not MS-DOS it existed already very long before that was
made, starting at 1963.

You are perfectly right. :-)

--
http://www.skyscan.be
Nov 22 '05 #6

"Olaf Baeyens" <ol**********@skyscan.be> wrote in message
news:42***********************@news.skynet.be...
> 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.

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.
Nov 22 '05 #7
Michael A. Covington <lo**@ai.uga.edu.for.address> wrote:
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.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #8

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Michael A. Covington <lo**@ai.uga.edu.for.address> wrote:
> 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.


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.
Nov 22 '05 #9

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

Similar topics

3
by: Cherif Diallo | last post by:
Hi I have a trivial question for the experts. I would lilke to read be able to read a text file that could contain french characters with accents. I'm opening the file with the...
2
by: DonD | last post by:
I have a form that allows a user to upload a file. When they select a file (onChange), I call a JS function that analyzes the filename for specific keywords and then populates a multiple select box...
7
by: garthb | last post by:
Hello, In Mozilla (Firefox 1.0.7) I can cloneNode a file input element that has a selected file value and appendChild it to another form without a problem. IE 6 loses the selected file value....
8
by: Al Knowles | last post by:
I have researched and tried every method I can find for passing a two-page tif file from a VB6 application to a web service via XML. These include XMLTextReader.ReadBase64, Convert.FromBase64,...
5
by: zambak | last post by:
Hi I have assignment for some wierd compression alghoritam that will read in from a file convert characters to 5 bit codes and then write out compressed version of the original file. For...
4
by: Carlo Marchesoni | last post by:
I really don't achieve to read a simple 'input.txt' with the following content: Jürg (Hex: 4a fc 72 67) to an identical 'output.txt' I do the following (and tried with tons of different...
29
by: list | last post by:
Hi folks, I am new to Googlegroups. I asked my questions at other forums, since now. I have an important question: I have to check files if they are binary(.bmp, .avi, .jpg) or text(.txt,...
4
by: kyle christian | last post by:
I am trying to save the high scores of a game I made. Now Im stumped on trying to search through the file. Should I use a string, array, or one of the STL containers to manipulate the information...
7
by: Quizzed | last post by:
Hi, Using MS Access '97, i run a query over a table and need and then export the results into a txt file using the ms access wizard and an export specification. The problem i have is with a field...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.