问题
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?
回答1:
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();
来源:https://stackoverflow.com/questions/13342988/read-embedded-text-file-as-string-array-c