473,322 Members | 1,714 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,322 software developers and data experts.

Reading copyright character from file with StreamReader

Hi,

I am trying to read a file, make changes, and write it to a new file.
The original file has the copyright character © which is ascii 169 I
believe, which is more than 7 bits. I am using typical StreamReader
object to read in the file, but it is not getting it correctly. If I
make the encoding type Ascii, it turns it into a question mark. If I
use UTF7 or UTF8, it ignores it. Unicode was jibberish. Any ideas?
Here is the file I am reading,
VersionLegalCopyright="©2005 All rights reserved."

and here is the code

StreamReader sr = null;
StreamWriter sw = null;
sr = new StreamReader(projectFile, Encoding.ASCII);
sw = new StreamWriter(tempProjectFile, false, Encoding.ASCII);
string line = String.Empty;

while ((line = sr.ReadLine()) != null)
{
// TODO: with regex's !!!
if (line.IndexOf("...") > 0)
sw.WriteLine("something");
else if ....
..
..
..
else
sw.WriteLine(line);
}
sw.Close();
sr.Close();

Thanks,

Ed
Nov 17 '05 #1
5 5794

"Ed West" <we**@westville.com> wrote in message
news:OY*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to read a file, make changes, and write it to a new file. The
original file has the copyright character © which is ascii 169 I believe,
which is more than 7 bits. I am using typical StreamReader object to read
in the file, but it is not getting it correctly. If I make the encoding
type Ascii, it turns it into a question mark. If I use UTF7 or UTF8, it
ignores it. Unicode was jibberish. Any ideas? Here is the file I am
reading,


Do you happen to know what Codepage the file is encoded with? I would guess
Windows-1252(Latin I), so take a shot at using the encoding created by:

Encoding.GetEncoding(1252);
Nov 17 '05 #2

"Ed West" <we**@westville.com> wrote in message
news:OY*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to read a file, make changes, and write it to a new file. The
original file has the copyright character © which is ascii 169 I believe,
which is more than 7 bits. I am using typical StreamReader object to read
in the file, but it is not getting it correctly. If I make the encoding
type Ascii, it turns it into a question mark. If I use UTF7 or UTF8, it
ignores it. Unicode was jibberish. Any ideas? Here is the file I am
reading,


Do you happen to know what Codepage the file is encoded with? I would guess
Windows-1252(Latin I), so take a shot at using the encoding created by:

Encoding.GetEncoding(1252);
Nov 17 '05 #3
Ed West <we**@westville.com> wrote:
I am trying to read a file, make changes, and write it to a new file.
The original file has the copyright character © which is ascii 169 I
believe, which is more than 7 bits.
There's no such thing as "ASCII 169" - ASCII doesn't have any values
over 127.
I am using typical StreamReader
object to read in the file, but it is not getting it correctly. If I
make the encoding type Ascii, it turns it into a question mark. If I
use UTF7 or UTF8, it ignores it. Unicode was jibberish. Any ideas?
Here is the file I am reading,


<snip>

You can't just guess at the encoding - you need to know what it is. It
may well be ISO-8859-1 (code page 28591) or the default encoding for
the platform (Encoding.Default) but you should understand what's
generating the file, and what encoding it will have used.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Ed West <we**@westville.com> wrote:
I am trying to read a file, make changes, and write it to a new file.
The original file has the copyright character © which is ascii 169 I
believe, which is more than 7 bits.
There's no such thing as "ASCII 169" - ASCII doesn't have any values
over 127.
I am using typical StreamReader
object to read in the file, but it is not getting it correctly. If I
make the encoding type Ascii, it turns it into a question mark. If I
use UTF7 or UTF8, it ignores it. Unicode was jibberish. Any ideas?
Here is the file I am reading,


<snip>

You can't just guess at the encoding - you need to know what it is. It
may well be ISO-8859-1 (code page 28591) or the default encoding for
the platform (Encoding.Default) but you should understand what's
generating the file, and what encoding it will have used.

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

Jon and Daniel,

Thanks for the reply....

The file is actually a VB project file (*.vbp). I am automating
changing the build numbers, etc. Anyway, Encoding.GetEncoding(1252)
seemed to work.

Thanks again..

Ed
Jon Skeet [C# MVP] wrote:
Ed West <we**@westville.com> wrote:
I am trying to read a file, make changes, and write it to a new file.
The original file has the copyright character © which is ascii 169 I
believe, which is more than 7 bits.

There's no such thing as "ASCII 169" - ASCII doesn't have any values
over 127.

I am using typical StreamReader
object to read in the file, but it is not getting it correctly. If I
make the encoding type Ascii, it turns it into a question mark. If I
use UTF7 or UTF8, it ignores it. Unicode was jibberish. Any ideas?
Here is the file I am reading,

<snip>

You can't just guess at the encoding - you need to know what it is. It
may well be ISO-8859-1 (code page 28591) or the default encoding for
the platform (Encoding.Default) but you should understand what's
generating the file, and what encoding it will have used.

Nov 17 '05 #6

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

Similar topics

6
by: Einar Høst | last post by:
Hi I'm trying to learn a bit about performance, hope someone can help me out I have a text file with 8-bit characters in it. In order to improve performance, I'm using a BinaryReader instead of...
6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
0
by: Ed West | last post by:
Hi, I am trying to read a file, make changes, and write it to a new file. The original file has the copyright character © which is ascii 169 I believe, which is more than 7 bits. I am using...
13
by: mloichate | last post by:
I must read a very heavy-weight text plain file (usually .txt extension) )and replace a given character with another given character in all text inside the file. My application was working pretty...
3
by: leticia larrosa | last post by:
Hi, I try to read a file that have 8 bit character, but contain some character whose code is more than 128 (spanish character). When I read this file using ASCII (Dim oRead As StreamReader =...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
2
by: SteMc | last post by:
today I tackled, for the first time, opening and reading from a text file. Following the example on the MSDN and declared a variable, strline as a string and objstreamreader as a streamreader. ...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
5
by: Z.K. | last post by:
In C#, using the StreamReader, how do I detect when you get to the end of line. I am reading a text file using the Read() function and I need to detect the \n\r, but everything I try does not...
1
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.