3 Replies - 1500 Views - Last Post: 15 November 2009 - 11:26 AM Rate Topic: -----

#1 IniX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-December 08

Load text file & create new string for every line?

Posted 15 November 2009 - 09:26 AM

I have a text file which contains the following:

Quote

A
B
C


Now, I want to create a new string for every line (string1, string2, string3) until the end of the text file.
So string1 should contain "A" and string2 "B", etc.

How do I do this?
Is This A Good Question/Topic? 0
  • +

Replies To: Load text file & create new string for every line?

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: Load text file & create new string for every line?

Posted 15 November 2009 - 09:39 AM

List<string> lines = new List<string>();
using (StreamReader sr = new StreamReader(File.Open("mytextfile.txt", FileMode.Open, FileAccess.Read)))
{
	string line = null;
	while ((line = sr.ReadLine()) != null)
		lines.Add(line);
}

Was This Post Helpful? 0
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 809
  • View blog
  • Posts: 1,947
  • Joined: 04-October 09

Re: Load text file & create new string for every line?

Posted 15 November 2009 - 11:24 AM

String[] lines = File.ReadAllLines("mytextfile.txt");

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: Load text file & create new string for every line?

Posted 15 November 2009 - 11:26 AM

Doh...got my ass kicked! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1