Searching a csv file

Hi,

I am trying to search a csv file until it hits a null value. The csv file is set up in such a way that I can search line by line until the first cell is blank (MB/Code). At the moment I just want to find this null cell and get the program to return the value, and then I can find the Res-Code and do some further calculations. Below is an example of the file I am searching.

MB/Code Description Res-Code

D desc1
D01 desc2
D0101 desc3
A001023



Thanks,
Scott


Answer this question

Searching a csv file

  • james79

    I should've posted my code that I have written so far (the second part is what I am trying to sort out - readPath2)...

    using System;
    using System.IO;

    public class Reader
    {
    public static void Main()
    {
    string readPath = "Master-res2007.csv";
    string writePath = "Master-res2007.txt";
    string data;

    if(File.Exists(readPath))
    {
    StreamReader reader = new StreamReader(readPath);

    // Read to end of file
    string file = reader.ReadToEnd();

    StreamWriter writer = new StreamWriter(writePath);

    // Write to text file
    writer.WriteLine(file);

    reader.Close();
    writer.Close(); // Free resources

    }else{
    Console.WriteLine("The file: " + (readPath) + " could not be found");
    }

    string readPath2 = "D-Ground.csv";

    if(File.Exists(readPath2))
    {
    StreamReader reader2 = new StreamReader(readPath2);

    //Read single line of text
    data = reader2.ReadLine();

    int peek = reader2.Peek();


    //While loop to check for Res-Code

    reader2.Close();
    //writer2.Close(); // Free resources

    }
    }
    }

  • Nik_1982

  • Searching a csv file