Search code examples
c#file-iotext-filesstreamreader

I-V data parsing in textfile


I am using a source meter which sweeps current and measures voltage and finally export all I-V data through rs232. I write them into a textfile with the format as following; I1,V1,I2,V2,I3,V3... I split all "commas" with the "split" function but I don't know how I can keep I-V couples into an array and then I want to calculate each resistance of each I-V by simple I/V calculation.
Any help would be greatly appreciated.

public class Sample
{
public static void Main() {
    using (StreamReader reader = new StreamReader("myfilefile.txt")) {
        string line = null;
        while (null != (line = reader.ReadLine())) 
           {
            string[] values = line.Split(',');
           }
    }
}
} 

Solution

  • You could do something like this:

    for (int j = 0; j < values.Length; j += 2) {
        double i = double.Parse(values[j]);
        double v = double.Parse(values[j+1]);
        double r = v / i;
    }