Csharp extract data form a .csv file

149 Views Asked by At

I'm looking for a short code to give the user the possibilities to choose the city matching with the zip code he types on console. I have a csv file were all the France zip code are present. An example:

  • type the zip code : 75000

1 - paris 1er arrondissement 2 - paris 2eme arrondissement 3 - paris 3eme arrondissement 4 - paris 4eme arrondissement 5 - paris 5eme arrondissement 6 - paris 6eme arrondissement 7 - paris 7eme arrondissement 8 - paris 8eme arrondissement 9 - paris 9eme arrondissement ...

the user after that has to chose 1 , 2 ,... or 9. and this entry from the csv should be written in a text file.

1

There are 1 best solutions below

0
On

Reading from a file:

string line = "";
using (StreamReader sr = new StreamReader(filename))
{
    while((line = sr.ReadLine()) != null)
    {
        Console.WriteLine(line);
    }
}