Jump to content

Help, Appending to and Reading from txt file.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
katspn

katspn

    Newbie

  • Members
  • Pip
  • 3 posts
OK first of all I am writing a program which stores lists and updates deliveries as part of a university assigment.

I am trying to list the deliveries in a list box but can't seem to seperate it out.
This is what I have so far:-

System.IO.StreamReader deliveries = new System.IO.StreamReader("C:/..../Deliveries");
while (!deliveries.EndOfStream)
{
Temp = deliveries.ReadLine();
Array[]=Temp.Split(-); // this is where I am trying to seperate out the line
this.listbox.Items.Add(Array);
}

I can't seem to get this to work, I am trying to get the information from a line in the text file to go into the array spliting each section of the txt file where the dashes appear, and then place it into the listbox, I can not get thee the .split(-) to work

Any help? please.:crying:

Edited by katspn, 16 April 2010 - 01:39 AM.


#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
do you have to use a text file or can you use XML? If you have to use the text file there should be a specific character in the line that tells you how to split. According to your code (BTW please use [CODE] tags next time) i'm assuming that the '-' character is your "splitter." You should be able to loop through the array and add each item to the list box. If your using XML you can deserialize the objects and loop through those. I would try using a foreach or a for loop and add each item instead of the entire array and see if that works.
-CDG10620
Software Developer