我该怎么做? 我的hello.txt字符串是:
string hello = Properties.Resources.hello;
我希望如此:
Random rand = new Random();
IEnumerable<string> lines = File.ReadLines(hello);
var lineToRead = rand.Next(1, lines.Count());
var line = lines.Skip(lineToRead - 1).First();
txtbx_output.Text = line.ToString();
这对我来说没有任何问题:
IEnumerable<string> lines = File.ReadAllLines(@"my pathblabla\Text\hello.txt");
但不是资源!
这让我很生气
答案 0 :(得分:1)
试试这个:
string hello = Properties.Resources.hello;
Random rand = new Random();
IEnumerable<string> lines = hello.Split(new[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries).ToList();
var lineToRead = rand.Next(1, lines.Count());
var line = lines.Skip(lineToRead - 1).First();
txtbx_output.Text = line.ToString();