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 MathewsPosted May 11, 2010, 1:54 AM
Otherwise you need to store all possible delimeters in your code and need to try each during stream line read
yamidPosted May 10, 2010, 2:18 PM
Cheers,
CrishPosted May 10, 2010, 12:39 PM
http://www.daniweb.com/forums/thread18000.html#
Jaish MathewsPosted May 10, 2010, 12:37 PM
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)
{
}
}