M
myjunkbuster
Howdy,
I have a simple C# program that opens a file for reading a text file,
creates a new file for writing, reads a line from the source file and writes
it to the target file. I did this using StreamReader and StreamWriter. I'm
doing this one line at a time on purpose because I want to strip out certain
things and save results in a different file. In comparing the two files I
saw that the target file had ? char where in the source file it had a -
character.
I looked at that the source file's - character via a hex editor and it has a
hex value of 96. Other - characters in the source file have a hex value of
2D. These 2D guys were written to the target file just fine. So it seems
that StreamReader doesn't know what the hex 96 - character is and is
replacing it with a ? character.
Instead of writing to a file I put in a Console.Write and it too wrote the ?
character to the screen. So it seems to me that the problem is with
StreamReader and not the StreamWriter. I also tried specifying various
encoders on the open like Default, ASCII, UTF7, UTF8 and none allowed
StreamReader to read that character.
So it looks like I'm going to have to do a replace on the hex 96 - character
with the hex 2D - character before I copy the file over. This may work but
perhaps there are other special characters in these files that won't be
processed correctly. So I'm looking for a better solution.
Any suggestions would be most appreciated.
Scott
I have a simple C# program that opens a file for reading a text file,
creates a new file for writing, reads a line from the source file and writes
it to the target file. I did this using StreamReader and StreamWriter. I'm
doing this one line at a time on purpose because I want to strip out certain
things and save results in a different file. In comparing the two files I
saw that the target file had ? char where in the source file it had a -
character.
I looked at that the source file's - character via a hex editor and it has a
hex value of 96. Other - characters in the source file have a hex value of
2D. These 2D guys were written to the target file just fine. So it seems
that StreamReader doesn't know what the hex 96 - character is and is
replacing it with a ? character.
Instead of writing to a file I put in a Console.Write and it too wrote the ?
character to the screen. So it seems to me that the problem is with
StreamReader and not the StreamWriter. I also tried specifying various
encoders on the open like Default, ASCII, UTF7, UTF8 and none allowed
StreamReader to read that character.
So it looks like I'm going to have to do a replace on the hex 96 - character
with the hex 2D - character before I copy the file over. This may work but
perhaps there are other special characters in these files that won't be
processed correctly. So I'm looking for a better solution.
Any suggestions would be most appreciated.
Scott