|
-
October 13th, 2005, 08:18 AM
#1
text file
I have a text file that looks like the following...
Name | Title
Dave | Mr
Mark | Sir
John | Dr
I need to open the file (c:\list.txt) and add each line(witch will vary) to a string. so i will end up with an array of strings. and when someone adds a person to the list the program when run again will be able to add an extra plac in the array.
I basicly need the reading the lines of a file into an array part.
can some one please help?
Tanks in advance,
David Bell
-
October 13th, 2005, 08:39 AM
#2
Re: text file
Maybe you could do it like this:
Code:
static void Main(string[] args)
{
System.Collections.ArrayList pArray = new ArrayList();
System.Collections.Hashtable pHash = new Hashtable();
// open stream reader
System.IO.StreamReader pSR = new StreamReader("test.txt");
string strLine = null;
while ((strLine = pSR.ReadLine()) != null)
{
// add the line to an array
pArray.Add(strLine);
// or split the string and add the part into a hash table
string[] strParts = strLine.Split('|');
string strName = strParts[0];
string strTitle = strParts[1];
pHash.Add(strName, strTitle);
}
// close the stream reader
pSR.Close();
}
You should ofcourse do some error checking.
-petter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|