0

so far:

List<string> names = Properties.Resources.first_names.ToArray().ToList();

produce wrong result,

the txt is like=> "Shirley","Rose","Sean","Jeremy"

Halid
  • 448
  • 7
  • 16
  • possible duplicate of [How to read embedded resource text file](http://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file) – NASSER Aug 26 '15 at 15:03
  • not about embedding its about converting to list @X-TECH – Halid Aug 26 '15 at 15:07

2 Answers2

2

Use a regex to split on the commas outside of the quotes like so:

var names = Regex.Split(Properties.Resources.first_names, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");

Then loop over each entry and remove the quotes like so:

for (int i = 0; i < names.Length; i++)
{
    names[i] = names[i]Replace("\"", "");
}
TheLethalCoder
  • 6,668
  • 6
  • 34
  • 69
1

To read text file contents from resources and convert to list, try this:

byte[] file = Properties.Resources.myResourceFile;
string text;
using (Stream stream = new MemoryStream(file))
{
     using (StreamReader reader = new StreamReader(stream))
     {
          text = reader.ReadToEnd();
     }
}
var names = text.Split(',').ToList();
NASSER
  • 5,900
  • 7
  • 38
  • 57