473,804 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,
VersionLegalCop yright="©2005 All rights reserved."

and here is the code

StreamReader sr = null;
StreamWriter sw = null;
sr = new StreamReader(pr ojectFile, Encoding.ASCII) ;
sw = new StreamWriter(te mpProjectFile, false, Encoding.ASCII) ;
string line = String.Empty;

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

Thanks,

Ed
Nov 17 '05 #1
5 5857

"Ed West" <we**@westville .com> wrote in message
news:OY******** *****@TK2MSFTNG P11.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.GetEnc oding(1252);
Nov 17 '05 #2

"Ed West" <we**@westville .com> wrote in message
news:OY******** *****@TK2MSFTNG P11.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.GetEnc oding(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.Defau lt) but you should understand what's
generating the file, and what encoding it will have used.

--
Jon Skeet - <sk***@pobox.co m>
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.Defau lt) but you should understand what's
generating the file, and what encoding it will have used.

--
Jon Skeet - <sk***@pobox.co m>
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.GetEnc oding(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.Defau lt) 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
3554
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 a StreamReader. I've made two versions of my method, one which uses typesafe code, and one which uses unsafe code with pointers. I've read several places that direct pointer access will eliminate bounds-checking when accessing an array, and would...
6
44126
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
326
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 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...
13
3977
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 well with this below shown code (code placed in a buttonclick event after selecting the file in a normal OpenFileDialog): --------------------------------- System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\1.txt"); string all =...
3
2351
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 = New StreamReader("C:\...\name.txt", System.Text.Encoding.ASCII)), this special characters aren't appear.
9
6791
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
7
7774
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 strReturn += input + vbCrLf input = sr.Read
2
1287
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. Basically I read in a line of a text file - this works fine. I then read in another line. This works fine However, the third time round I read character by character, until I get to to the 40th character on the line, because this is the position
4
12812
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
5
8790
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 work. I am sure that this probably fairly simple, but I have not been able to figure it out. Z.K.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.