Reading from a CSV File and Searching for a Record in C# (Simple)

8
17



Reading from a CSV File and Searching for a Record in C#

Greetings, I am back and shall be showing you how to read a record from a CSV file (or a text file with comma seperated values) using C#. To read a file using C# you have to simply read every line of the file into an array, then add each field of a record to an array and check if a field matches a search term, if it has, the record was found in the file, of not continue searching the file. If you have searched the file and no record was found, then the record didn’t exist in the file or an error occured, if this happens, we can print a message to inform the user.

Subscribe to keep notified when I upload:

Social media:
Instagram:
Twitter:

Reading from a CSV File and Searching for a Record in C#

Nguồn:https://wijstaanvooronzegrondrechten.org/

8 COMMENTS

  1. Dear Max,
    Your explanation is superb, could you let me know what if I want to get a specific value of a line
    Let me give an example..
    I have a csv file ABC.Txt file with contents as indicated below

    Name, Age, TelNum, Emailid

    Chris, 42, 5555, chris.walker@gmail.com

    Rob, 35, 6666, rob.randell@gmail.com

    from my C# Script, i want to vlookup by a specific name and get information like age (or) TelNum (or) EmailId.

    e.g for Chris, if I query for Emailid , i must get his emailid which is chris.walker@gmail.com.

    Appreciate if Could I get a typical code example for this

    Cheers!!

    Venkat

LEAVE A REPLY

Please enter your comment!
Please enter your name here