C# - Filling an array from a file...

Associate
Joined
18 Oct 2002
Posts
220
Location
London, UK
Hi All,

I'm slowly getting to grips with C#, but I've hit a problem with something...

I've written an application the reads in certain information from a config file.

Currently I keep all the information I need (hostnames) in 1 line, and comma delimit it. I then read the file with something like the below.

using (FileStream myFileStream = new FileStream(myFile, FileMode.Open, FileAccess.Read, FileShare.None))
{
using (StreamReader myStreamReader = new StreamReader(myFileStream))
{
string data = myStreamReader.ReadLine();
string[] myArray = data.Split(new char[] { ',' });
return myArray;
}
}

which splits it at every comma, then fills the array, I then perform actions on each value in the array. My problem is that this gets messy when the line in the files gets bigger. I want to be able to have each entry on a new line.

Is there a way I can split on '\r\n' or something? Or is there a better way of doing it than this?

Cheers,
Melon.
 
Back
Top Bottom