Extracting the values from a CSV using c#

So, today I was working on implementing a new feature which involved extracting the values off a comma separated value (CSV). Naturally I have a Utility namespace in my core library with a class called StringManipulation. In it I have a method that generates and returns a CSV, so I needed one to reverse the CVS generation, i.e. get the values off any CSV object. Here’s my solution;

public static void Main()
     Console.WriteLine("Please enter names separated by a comma:");

     foreach(string name in ExtractValues(Console.ReadLine()))

     Console.WriteLine("Finished printing.");

public static string[] ExtractValues(string commaSeparatedValue) 
     return commaSeparatedValue.Split(',');

Edit: Changed the ExtractValues(), thanks to :ivowiblo pointing it out, from .Split(“,”.ToCharArray()); to .Split(‘,’);

Posted in Uncategorized

4 thoughts on “Extracting the values from a CSV using c#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s