472,804 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

StreamReader, StringReader, TextReader

StreamReader says it is designed to read a stream of characters
StringReader says it is designed to read a string
TextReader says it is designed to read a sequential list of characters.

I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's
the difference?

--
TFWBWY...A
Nov 21 '05 #1
2 16062
The difference is in the source of the characters. The Stream reader
gets its data from a stream. This could be a memory stream, a file
stream, a stream from a serial port. A stream might come from a video
capture device. It provides a consistent methodology for reading data,
regardless of the source. The StringReader reads data from another
string. The TextReader reads data from a text file.

Nov 21 '05 #2
Bryan,
In addition to the other comments:

Short answer: Its called Inheritance! Remember Inheritance is one of the
major tenants of OO.

StreamReader inherits from TextReader
StringReader inherits from TextReader

In other words: both StreamReader & StringReader are types of TextReaders.
Long answer:

TextReader has all the common logic on reading characters, it declares the
"contract" on how to read characters. StreamReader has the specifics on
reading characters from a Stream (aka a File) it fills in the specific of
the "contract" to read characters from a Stream. While StringReader has the
specifics on reading characters from a String (for example the clipboard or
a TextBox) it fills in the specifics of the "contract" to read characters
from a String.
If I am writing a routine that needs to read Text, generally I will write it
based on a TextReader. This way I can pass it either a StreamReader or a
StringReader & the routine itself is non the wiser. Additionally if a new
type of TextReader is defined, my routine will be able to handle it also...

Hope this helps
Jay

"Bryan Dickerson" <tx******@netscape.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
| StreamReader says it is designed to read a stream of characters
| StringReader says it is designed to read a string
| TextReader says it is designed to read a sequential list of characters.
|
| I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's
| the difference?
|
| --
| TFWBWY...A
|
|
Nov 21 '05 #3

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

Similar topics

4
by: Mike | last post by:
I created a StreamReader object from a local file on my c:\ drive StreamReader srTemp = new StreamReader("C:\\myFile.txt") I then used a RegEx to strip out all the html and save what's left to...
6
by: Jesper | last post by:
Hi, Im using a code snippet that reads a text file from disc and processes it using stream = new StreamReader(filename); Is it possible to assign a String instead of a file as the source of...
1
by: AMP | last post by:
Hello, I am trying to see if a FileStream Opened using an"if" clause: FileStream infile = new FileStream("c:\\blink2.txt", FileMode.Open, FileAccess.Read, FileShare.Read); if (infile==0)..... ...
11
by: info | last post by:
Hi All, How can i rewind the following sile stream: TextReader tr = new StreamReader(File.Open(fileName, FileMode.Open)); Is there a dedicated method or shall I close and re-open the...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
3
by: trint | last post by:
When testing locally with: TextReader tr = new StreamReader(@"C:\gcc.set"); Now that I have uploaded this to the server on the net, that locations permissions are denied. How can I change this to...
1
by: Rene | last post by:
Hi, I decided to take a closer look at the TextWriter and TextReader abstract classes just for fun. While poking around, I noticed that the TextWriter class includes an 'Encoding' property in...
3
by: =?Utf-8?B?Qm9zc2ll?= | last post by:
Hi All, I am having a little trouble with a StreamReader. I am currently reading a pipe delimited file with around 1.8 million records (total size 150MB) and, based on a flag, insert update or...
3
by: Tony Johansson | last post by:
Hello! I just wonder in this specific case is it any advantage to use a TextReader a reference to a StreamReader ? Try { TextReader tr = new StreamReader(locationTextBox.Text); Try {
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.