Welcome to Dream.In.Code
Become a C# Expert!

Join 150,394 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,035 people online right now. Registration is fast and FREE... Join Now!




Reading a file, Array issue

 
Reply to this topicStart new topic

Reading a file, Array issue

reCoded
5 Mar, 2008 - 09:55 PM
Post #1

D.I.C Head
**

Joined: 25 Feb, 2008
Posts: 166

Hey guys,

I am reading in a text file and I want to store every string that starts with lets say a '+' into an array.

csharp

-----------------------------------------------------------------------------------------------------------------------
string array = new array[100];
int count = 0;

while ((wholeLine = reader.ReadLine()) != "</html>")
{


if (wholeLine.Contains("+"))
{
Console.WriteLine(wholeLine);

array[count] = wholeLine;
}

count++;

}

------------------------------------------------------------------------------------------------------------------------


Would this be a good way to approach this problem?

Thanks in advance,
recoded

This post has been edited by PsychoCoder: 5 Mar, 2008 - 09:59 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Reading A File, Array Issue
5 Mar, 2008 - 10:06 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You will also need to make sure you're going past the end of the file. otherwise you will have an unhandled exception on your hands. To check for this you will use the Peek Method of the StreamReader Class, which I imagine your reader object is


csharp

string array = new array[100];
int count = 0;

//make sure we're not at the end of the file
while(!(reader.Peek = -1))
{
while ((wholeLine = reader.ReadLine()) != "</html>")
{
if (wholeLine.Contains("+"))
{
Console.WriteLine(wholeLine);
array[count] = wholeLine;
}
count++;
}
}



Hope that helps smile.gif
User is online!Profile CardPM
+Quote Post

reCoded
RE: Reading A File, Array Issue
5 Mar, 2008 - 11:42 PM
Post #3

D.I.C Head
**

Joined: 25 Feb, 2008
Posts: 166

Yes it does thankyou!

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Reading A File, Array Issue
6 Mar, 2008 - 05:43 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help. Now tell all your friends about us smile.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:07PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month