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#?
-
4Making some efforts and searching about your problemSteve– Steve2017-05-04 08:43:46 +00:00Commented May 4, 2017 at 8:43
-
what ve you done?Dan Nguyen– Dan Nguyen2017-05-04 08:44:31 +00:00Commented May 4, 2017 at 8:44
-
Stack Overflow is not a free code writing service. You are expected to try to write the code yourself. After doing more research if you have a problem you can post what you've tried with a clear explanation of what isn't working and providing a minimal reproducible example. I suggest reading How to Ask a good question and the perfect question. Also, be sure to take the tour.Igor– Igor2017-05-04 08:45:48 +00:00Commented May 4, 2017 at 8:45
-
4Possible duplicate of Read a CSV file in to an array using C#EpicKip– EpicKip2017-05-04 08:46:14 +00:00Commented May 4, 2017 at 8:46
-
1Possible duplicate of Reading CSV file and storing values into an arrayPMerlet– PMerlet2017-05-04 08:52:41 +00:00Commented May 4, 2017 at 8:52
|
Show 3 more comments
1 Answer
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);
}
1 Comment
Ian Johnson
Cheers, this is exactly what I needed.