1

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?

Community
  • 1
  • 1
LordAro
  • 1,269
  • 3
  • 18
  • 35

1 Answers1

3

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();
Johan Larsson
  • 17,112
  • 9
  • 74
  • 88
  • I didn't (or haven't yet) bother with the extension method, but that works great, thanks :) – LordAro Nov 12 '12 at 11:50
  • Might i ask how you actually add that to your solution? Sorry if this is a stupid question – triunenature Sep 15 '14 at 05:22
  • 1
    The method GetLines must be in a static non-generic class. It is called an [Extension Method](http://msdn.microsoft.com/en-us//library/bb383977.aspx) – Johan Larsson Sep 15 '14 at 06:27