Search code examples
c#arraysstringfile-ioembedded-resource

Read embedded text file as string array (C#)


I'm trying to read an embedded textfile.

The text file has the structure:

Word1
Word2
Word3
...

I'm trying to get this into a string array, but am unable to do so.

I mean, i've come across this: How to read embedded resource text file but this only reads the file as a string and while i could read the string, then separate it out line-by-line, there seems like there should be a simpler solution.

Is there?


Solution

  • I use this extension method for splitting lines:

    public static string[] GetLines(this string s)
    {
        return s.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
    }
    

    Then you can do:

    string[] strings = Properties.Resources.YourResource.GetLines();