Hi Guys,
I have a text file (tab/space,comma delimited) with some
header. maybe we have some free space line need to be ignored . I want
to store them in some arrays for example~:
#Header of the file
#data
are double
#x , y, z, i, j
122 1222 122 45 23
12 188 85
65 25
18 58 454 545 58
23 45 87 52 32
...
I want to have
this arrays:
X[]={122 12 18 23 ....}
y[]={1222 188 58 45 ...}
z[]={122
85 454 87 ...} and the same for i,j array.
or this array:
A[][]
in which the inner array is from 0 to 4 representing ( x,y,z,i,j) and
the second jagged part is the corresponding data.
Thanks
Loading

Jaish MathewsRank #225 · 11K reputationPosted May 10, 2010, 8:37 AM EDT
My text file was like
#Header of the file
#data are double
#x , y, z, i, j
122 1222 122 45 23
12 188 85 65 25
18 58 454 545 58
23 45 87 52 32
and code is
static void Main(string[] args)
{
List<Array> list = new List<Array>();
using (StreamReader sr = new StreamReader(@"c:\test.txt"))
{
while (!sr.EndOfStream)
{
string streamLine = sr.ReadLine();
if (!string.IsNullOrEmpty(streamLine) && !streamLine.StartsWith("#"))
{
Array lineArray = streamLine.Split(' ');
list.Add(lineArray);
}
}
}
//Accessing each array
foreach (Array line in list)
{
}
}
CrishRank #1,487 · 1.1K reputationPosted May 10, 2010, 8:39 AM EDT
http://www.daniweb.com/forums/thread18000.html#
yamid113 reputationPosted May 10, 2010, 10:18 AM EDT
Cheers,
Jaish MathewsRank #225 · 11K reputationPosted May 10, 2010, 9:54 PM EDT
Otherwise you need to store all possible delimeters in your code and need to try each during stream line read