I have a CSV list of player ID strings each on a different line. How do I go about storing each of the IDs in an array in C#?
Asked
Active
Viewed 5,206 times
-7
-
4Making some efforts and searching about your problem – Steve May 04 '17 at 08:43
-
what ve you done? – Dan Nguyen May 04 '17 at 08:44
-
[so] is *not* a free code writing service. You are expected to try to **write the code yourself**. After [doing more research](http://meta.stackoverflow.com/questions/261592) if you have a problem you can **post what you've tried** with a **clear explanation of what isn't working** and providing a **[mcve]**. I suggest reading [ask] a good question and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour]. – Igor May 04 '17 at 08:45
-
4Possible duplicate of [Read a CSV file in to an array using C#](http://stackoverflow.com/questions/12102804/read-a-csv-file-in-to-an-array-using-c-sharp) – EpicKip May 04 '17 at 08:46
-
http://stackoverflow.com/questions/16195497/c-sharp-csv-file-to-array-list – EpicKip May 04 '17 at 08:46
-
http://stackoverflow.com/questions/73385/asp-net-convert-csv-string-to-string – EpicKip May 04 '17 at 08:46
-
1 google search is all it takes – EpicKip May 04 '17 at 08:47
-
1Possible duplicate of [Reading CSV file and storing values into an array](http://stackoverflow.com/questions/5282999/reading-csv-file-and-storing-values-into-an-array) – PMerlet May 04 '17 at 08:52
1 Answers
2
You can start from this code, first read the file, second split the file since data is on different row, then store the result on array:
using (StreamReader sr = new StreamReader(@"C:\Folder\Book1.csv"))
{
string strResult = sr.ReadToEnd();
string[] result = strResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
}

Willy David Jr
- 8,604
- 6
- 46
- 57