473,804 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\\peop le.DAT");
StreamReader reader = theSourceFile.O penText();
StreamWriter writer = new StreamWriter(@" c:\\Documents and
Settings\\Rob\\ School\\CIS 252\\Ass2\\peop le.BAK",false);

string text;

do
{
text = reader.ReadLine ();
writer.WriteLin e(text);
Console.WriteLi ne(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.writeli ne(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 3970
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\\peop le.DAT");
StreamReader reader = theSourceFile.O penText();
StreamWriter writer = new StreamWriter(@" c:\\Documents and
Settings\\Rob\\ School\\CIS 252\\Ass2\\peop le.BAK",false);

string text;

do
{
text = reader.ReadLine ();
writer.WriteLin e(text);
Console.WriteLi ne(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.WriteLin e(null) and Console.WriteLi ne (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.writeli ne(text)......

It is delimited with a semi colon


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

--
Jon Skeet - <sk***@pobox.co m>
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.Pe ek()>=0)
{
Console.WriteLi ne(reader.ReadL ine().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\\peop le.DAT");
StreamReader reader = theSourceFile.O penText();
StreamWriter writer = new StreamWriter(@" c:\\Documents and
Settings\\Rob\\ School\\CIS 252\\Ass2\\peop le.BAK",false);

string text;

do
{
text = reader.ReadLine ();
writer.WriteLin e(text);
Console.WriteLi ne(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.writeli ne(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.WriteLi ne(reader.ReadL ine().ToString( ));


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

--
Jon Skeet - <sk***@pobox.co m>
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.co m> wrote in message
news:MP******** **************@ msnews.microsof t.com...
Kumar <ku************ *******@NoSpam. hotmail.com> wrote:
to read one line at a time u can use the following code


<snip>
Console.WriteLi ne(reader.ReadL ine().ToString( ));


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

--
Jon Skeet - <sk***@pobox.co m>
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.co m>
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
1514
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 monitor this text file and to be able to read only the new added line when it detect that a new line has been added. I don't want to read the whole file every time, this would be high time consuming.
7
2815
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 Col3 Col4 A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
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?
2
2501
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() { OperatingSystem os = Environment.OSVersion; AppDomain ad = Thread.GetDomain();
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 =...
9
35321
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 streamReader = new StreamReader(stream, Encoding.ASCII)) { string line = ""; DateTime currentDate = DateTime.Now.Date; while (streamReader.Peek() > -1)
5
3416
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 (using transaction) a insert query to Ms Sql server
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...
2
4194
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 garbage under ReadLine method. Does anybody have any idea on this issue? Thanks for your attention and kindly help! Regards,
0
9716
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
10354
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
10359
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
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
5536
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
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3837
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.