split text file into lines on C#?

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 4926 Views - Last Post: 20 December 2011 - 08:05 PM Rate Topic: -----

#1 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

split text file into lines on C#?

Posted 19 December 2011 - 12:06 PM

Hi i would require some assistance on how to split a text file into lines and making each line an array on c# using microsoft visual basic 2010?
Please could you help me with this as this one area i am struggling with.

thanks

Simon
Is This A Good Question/Topic? 0
  • +

Replies To: split text file into lines on C#?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:13 PM

The 'streamreader' namespace has a option called "readline". It returns a string for everyone in the file (basically separated by carriage returns). First problem down. The second problem - the array - is a simple one. you might want to use something like 'list<of string>' (so you can add directly to the container and it expands for you)... and basically each 'readline' in the streamreader you would .add to the collection.
Was This Post Helpful? 0
  • +
  • -

#3 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:20 PM

Thanks! dont mean to be rude but could you give me an example on how this could be implemented, would be much appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:25 PM

Sorry - basically any example would be giving away the homework problem. It's really that simple.

Stream reader & readline.
http://msdn.microsof...reamreader.aspx

You should be able to declare an array of strings alright, right?
Was This Post Helpful? 2
  • +
  • -

#5 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:27 PM

Ok thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#6 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:30 PM

Thanks that is awesome dude!

Il give it a shot1
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:50 PM

racidon: Why don't you next time hand to the lazy "coder" on a silver platter next time. The OP hasn't shown a single shred of evidence of putting in any effort in doing the simple task themselves.

I've got an object that read from a file. Tick
Does that object provide a way of reading a line. Tick
So let me think what do put each line into an array?


Is it me? Or is Dream.In.Code attracting more and more lazy-assed people, that want to play at being toy programmers? OK here's the deal, I don't want to be bothered doing the thinking part. So give me the "money" (Code).

Put it this way. If they want to get their hands on some money without the effort of making it.
It's like they are walking and browsing down the street, and spot a bank (Dream.In.Code). They've got loads of money, I'll "use" theirs.
"Hello {Insert Cashier Name}, would you be awful kind and put the contents of your cash drawer in this bag since my funds are running a little short. Thank You.". And the Cashier actually doing it.

This post has been edited by AdamSpeight2008: 19 December 2011 - 12:56 PM

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:53 PM

@raic - let's not make it too simple for the OP... I mean this is *THEIR* homework!

Oh, and if I am not mistaken this typical homework assignment is used to teach loops and the streamreader. Trying to short circuit everything with "File.ReadlAllLines" bypasses that specific area.

Edit:ah it looks like Adam covered my second thought!
Was This Post Helpful? 0
  • +
  • -

#9 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:53 PM

huh? i am confused this does not make sense?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:54 PM

*WHAT* doesn't make sense?
Was This Post Helpful? 0
  • +
  • -

#11 Simon-Thomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

Re: split text file into lines on C#?

Posted 19 December 2011 - 12:55 PM

never mind!
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5520
  • View blog
  • Posts: 11,829
  • Joined: 02-June 10

Re: split text file into lines on C#?

Posted 19 December 2011 - 02:55 PM

Solution provided by racidon has been hidden. No need to repeat *why* as it has been said many time. A shame someone else didn't do this while they were telling racidon off. Now it's kind of like closing the barn door after the horse has escaped.

This post has been edited by tlhIn`toq: 19 December 2011 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

#13 racidon  Icon User is offline

  • D.I.C Head

Reputation: 59
  • View blog
  • Posts: 172
  • Joined: 27-August 11

Re: split text file into lines on C#?

Posted 20 December 2011 - 06:49 AM

View Postmodi123_1, on 19 December 2011 - 12:53 PM, said:

@raic - let's not make it too simple for the OP... I mean this is *THEIR* homework!

Oh, and if I am not mistaken this typical homework assignment is used to teach loops and the streamreader. Trying to short circuit everything with "File.ReadlAllLines" bypasses that specific area.

Edit:ah it looks like Adam covered my second thought!

Care to point out where Simon-Thomas has stated this is homework?
I'm aware of basic rules of the forum. But I'm also aware that to start to learn programming you need examples, that's why MSDN has the examples there, however they do not for the ReadAllLines method.
Yes that's most likely because of how simple the method is, but so is the iteration of getting each line on a text document, so if a user is asking how to do it, most likely they will not understand how "signatures" work, I know this because I've helped teach a Java programming class and one thing all the people new to programming struggled with was "objects" and "signature" definitions (along with such things as UML).
Was This Post Helpful? 1
  • +
  • -

#14 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: split text file into lines on C#?

Posted 20 December 2011 - 07:19 AM

:offtopic:

OK! Then give an example that isn't the code that he has to figure out.

Give the example of some general syntax and implementation for the given class, but not related to the current topic. Then the OP will figure out what he needs to do from there and do it.

This is so that the OP will actually learn instead of copying and pasting in your code. That way he won't know what it does neither how it does it, he just uses it because it works.

Following that curve he won't be able to learn advanced topics that rely on the basics like this. It's by giving him explicit code you actually harm him, not help him. That's why there is homework in the first place. Homework are given so that the students can learn something (or to better understand the already learned things).

Also if the OP doesn't understand something that is used for a basis for this topic then refer him to some documentation where he can learn about that and then advance. Not just rush in-head on and when he sees that the door is thick and hard get a concussion. It's also because of that why we don't give finished code.

You can't discuss advanced topics if you didn't learn the basics! Period. :D

This post has been edited by RexGrammer: 20 December 2011 - 07:26 AM

Was This Post Helpful? 0
  • +
  • -

#15 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: split text file into lines on C#?

Posted 20 December 2011 - 07:43 AM

View Postracidon, on 20 December 2011 - 09:49 AM, said:

View Postmodi123_1, on 19 December 2011 - 12:53 PM, said:

@raic - let's not make it too simple for the OP... I mean this is *THEIR* homework!

Oh, and if I am not mistaken this typical homework assignment is used to teach loops and the streamreader. Trying to short circuit everything with "File.ReadlAllLines" bypasses that specific area.

Edit:ah it looks like Adam covered my second thought!

Care to point out where Simon-Thomas has stated this is homework?


Use this rule-of-thumb: If the member has 1 post, the default profile image, ask a question about how to do something and post no code, then 99% of the time they are a student and are asking for you to do their homework for them.

For the most part, the poster is not going to say, "Can you help with my homework?", because the post box actually states that we will not do their homework for them. So using the logic, "Well he didn't say it was homework" is naive.

Many of us have been here long enough to be able to spot members who are here solely for us to do their homework for them.

Have you noticed how Simon-Thomas has not denied that this is for homework? He's read us saying it's for his homework, and he has not denied it. That should tell you something.
Was This Post Helpful? 3
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2