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)
- {
- // bJump = false;
- // Console.WriteLine(line);
- string[] fields = line.Split('|');
- // I want to say fields[][] = line.Split because i am //accessing fields[i,1] and [i,2] down in the code but i am //getting the error of cannot convert string to string[]
- 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; //Data
- Result[i, 1] = "Track ID";
- Result[i, 2] = "DATUM"; //Datum from the header
- Result[i, 3] = fields[i,1]; //Test Code
- Result[i, 4] = "1"; // Test Channel
- Result[i, 5] = "Test Value";
- Result[i, 6] = "1"; //Test Frequency
- Result[i, 7] = fields[i,5]; // Status
- Result[i, 8] = "1"; // Test Voltage
- if (wasParsedOK1 && wasParsedOK2)
- {
- Result[i, 9] = (parsed_field1 - parsed_field2).ToString(); // Lower Limit
- Result[i, 10] = (parsed_field1 + parsed_field2).ToString(); // Upper Limit
- }
- 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";
- }
Tapan PatelPosted Sep 12, 2016, 10:24 AM
Hesham HassaneinPosted Sep 12, 2016, 9:38 AM
Tapan PatelPosted Sep 12, 2016, 9:35 AM
Hesham HassaneinPosted Sep 12, 2016, 9:29 AM
Tapan PatelPosted Sep 12, 2016, 9:22 AM