将嵌入式文本文件读取为字符串数组(C#) [英] Read embedded text file as string array (C#)
本文介绍了将嵌入式文本文件读取为字符串数组(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.
在那里吗?
推荐答案
我使用此扩展方法分割行:
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();
这篇关于将嵌入式文本文件读取为字符串数组(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文