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

Reading one line at a time and parsing - StreamReader HELP!?

Hello all
I have a project that I have to read the file - which I have done I
can see the file output. I then need to read the line - parse the
line into three separate values (there are 3 = name age and gender)
static void DoPartD()
{

FileInfo theSourceFile = new FileInfo(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.DAT");
StreamReader reader = theSourceFile.OpenText();
StreamWriter writer = new StreamWriter(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.BAK",false);

string text;

do
{
text = reader.ReadLine();
writer.WriteLine(text);
Console.WriteLine(text);
} while (text != null);
reader.Close();
writer.Close();
}

I am not sure how to read just one line at a time to parse them

like I said, I can see all the lines when
Console.writeline(text)......

It is delimited with a semi colon

Thanks

Rob

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 15 '05 #1
7 3934
BlueOysterCult <sc****@serv-dot-net.no-spam.invalid> wrote:
I have a project that I have to read the file - which I have done I
can see the file output. I then need to read the line - parse the
line into three separate values (there are 3 = name age and gender)

static void DoPartD()
{

FileInfo theSourceFile = new FileInfo(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.DAT");
StreamReader reader = theSourceFile.OpenText();
StreamWriter writer = new StreamWriter(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.BAK",false);

string text;

do
{
text = reader.ReadLine();
writer.WriteLine(text);
Console.WriteLine(text);
} while (text != null);
reader.Close();
writer.Close();
}

I am not sure how to read just one line at a time to parse them
You *are* already reading just one line at a time - although you ought
to break out of your loop as soon as text is null, rather than calling
writer.WriteLine(null) and Console.WriteLine (null) - it doesn't matter
for those two calls, but for other calls which use text, it may well.
like I said, I can see all the lines when
Console.writeline(text)......

It is delimited with a semi colon


So within your loop, where you've got writer.WriteLine and
Console.WriteLine, put the parsing code, which should probably use
String.Split.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
to read one line at a time u can use the following code
using System.IO;
using System;

public class cls
{

public static void Main()
{

FileInfo fl = new FileInfo("file.txt");
StreamReader reader = fl.OpenText();
while(reader.Peek()>=0)
{
Console.WriteLine(reader.ReadLine().ToString());
}

reader.Close();

}

}
"BlueOysterCult" <sc****@serv-dot-net.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Hello all
I have a project that I have to read the file - which I have done I
can see the file output. I then need to read the line - parse the
line into three separate values (there are 3 = name age and gender)
static void DoPartD()
{

FileInfo theSourceFile = new FileInfo(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.DAT");
StreamReader reader = theSourceFile.OpenText();
StreamWriter writer = new StreamWriter(@"c:\\Documents and
Settings\\Rob\\School\\CIS 252\\Ass2\\people.BAK",false);

string text;

do
{
text = reader.ReadLine();
writer.WriteLine(text);
Console.WriteLine(text);
} while (text != null);
reader.Close();
writer.Close();
}

I am not sure how to read just one line at a time to parse them

like I said, I can see all the lines when
Console.writeline(text)......

It is delimited with a semi colon

Thanks

Rob

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 15 '05 #3
Kumar <ku*******************@NoSpam.hotmail.com> wrote:
to read one line at a time u can use the following code
<snip>
Console.WriteLine(reader.ReadLine().ToString());


There's no need to call ToString() - ReadLine() already returns a
string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
yeah you are right.. bad habit.. I got used to use ToString() too much..
that too when I write code using notepad.. I tend to use it more often..
since i wouldnt have the help if IDE..

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP**********************@msnews.microsoft.com ...
Kumar <ku*******************@NoSpam.hotmail.com> wrote:
to read one line at a time u can use the following code


<snip>
Console.WriteLine(reader.ReadLine().ToString());


There's no need to call ToString() - ReadLine() already returns a
string.

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

Nov 15 '05 #5
ugggg

I have tried everything - nothing is working

I can't get the syntax right-- I know its something.Split({";"});

etc but nothing is working
Forgive me - I am new to C#

R

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 15 '05 #6
myString.Split(';'); // This what you need?

This uses the params char[] sep overload. With params, the compiler is able to
accept an expanded parameter list to the function and shrink that down into the
required array for you. To explicitly package a character array you could use:

myString.Split(new char[] {';'});
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"BlueOysterCult" <sc****@serv-dot-net.no-spam.invalid> wrote in message
news:40********@127.0.0.1...
ugggg

I have tried everything - nothing is working

I can't get the syntax right-- I know its something.Split({";"});

etc but nothing is working
Forgive me - I am new to C#

R

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 15 '05 #7
BlueOysterCult <sc****@serv-dot-net.no-spam.invalid> wrote:
I have tried everything - nothing is working

I can't get the syntax right-- I know its something.Split({";"});

etc but nothing is working
Forgive me - I am new to C#


Have you looked closely at the documentation for String.Split, and the
example given?

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

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

Similar topics

4
by: Marty | last post by:
Hi everybody, Is it possible to do that in VB.NET: I have a text file that is filled with new lines of text every n seconds. This text file get very massive. I want to have my program to...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
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?
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
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...
9
by: haibhoang | last post by:
I have a Windows Service that is trying to parse a large (> 1Gig) text file. I am keep getting OutOfMemoryException exception. Here is the code that's having problem: using (StreamReader...
5
by: WoodenSword | last post by:
Hi, I am trying to read a huge text file (2GB) using StreamReader. I do this: Read a line (readline()) I process the line a bit (split it with delimeter and change fields a bit) execute...
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...
2
by: James Wong | last post by:
Dear all, I'm using StreamReader to read a text file containing BIG-5 data and found that no matter which encoding method in StreamReader's construction parameter, the BIG-5 contents become...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.