I would like to split the line from the csv file and save it into a multidimensional array but i am getting an error cannot convert type string into string[]. because i cannot say fields[][] = line.Split(|)
For example the line is:
1|2|3|4|5|6
1|6.9|GREATER THAN|%|29.844000|x|1
1|-27|LESS THAN|dBc|-30.51400|x|1
and i would like to subtract the third column from the second. Depending on the row number which is i in the following code. So i am using tryToparse as follows but the thing is that i want to access fields[i,2] and fields[i,1] and subtract or add them. but i cannot because i cannot use it in line.Split. How can i resolve this?. Thanks in advance
- while ((line = reader.ReadLine()) != null)
- {
-
-
- string[] fields = line.Split('|');
-
- int parsed_field1;
- int parsed_field2;
-
-
- for (int i = 0; i < count-1; i++)
- {
-
- bool wasParsedOK1 = Int32.TryParse(fields[i,1], out parsed_field1);
- bool wasParsedOK2 = Int32.TryParse(fields[i,2], out parsed_field2);
-
-
- Result[i, 0] = "PATS_TEST";
- if (isheader)
- {
-
- isheader = false;
- Result[i, 1] = "Track ID";
- Result[i, 2] = "DATUM";
- Result[i, 3] = fields[i,1];
- Result[i, 4] = "1";
- Result[i, 5] = "Test Value";
- Result[i, 6] = "1";
- Result[i, 7] = fields[i,5];
- Result[i, 8] = "1";
-
-
- if (wasParsedOK1 && wasParsedOK2)
- {
- Result[i, 9] = (parsed_field1 - parsed_field2).ToString();
- Result[i, 10] = (parsed_field1 + parsed_field2).ToString();
-
- }
- else if (!wasParsedOK2)
- {
- if (fields[2].Contains("GREATER THAN"))
- {
- Result[i, 9] = fields[i,1];
- Result[i, 10] = (Int32.Parse(fields[1])+10).ToString();
-
- }
- else if (fields[i,2].Contains("LESS THAN"))
- {
- Result[i, 9] = fields[i,1];
- Result[i, 10] = "0";
-
- }