Read embedded text file as string array (C#)

对着背影说爱祢 提交于 2021-01-29 02:54:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!