1

How can I do that? My string for hello.txt is:

string hello = Properties.Resources.hello;

and I want it so:

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();

This here works for me with no problems:

IEnumerable<string> lines = File.ReadAllLines(@"my pathblabla\Text\hello.txt");

but not as a resource !

This makes me very angry

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
User77778
  • 21
  • 3

1 Answers1

1

Try this :

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();
Abdellah OUMGHAR
  • 3,627
  • 1
  • 11
  • 16