I am trying to randomly read a huge .txt file. It has tons of paragraphs separated by a full line of empty space prior and post each paragraph. I would like each time I randomly read that it pulls up a full intact paragraph without any characters or words missing for the sake of context. I appreciated the help in advance.
I added a for loop just to test it out and see if I can at some point include a way to recognize consecutively running empty space. That would only work post already selected the starting point obviously if applied.
public static string GetRandomLine(string filename)
{
var lines = File.ReadAllLines(filename);
var lineNumber = _rand.Next(0, lines.Length);
string reply = lines[lineNumber] + lines[lineNumber + 30];
for(int a = 0; a <= 30; a++)
{
reply = reply + lines[lineNumber + a];
//The increment on the lineNumber is because I wanted to receive
//more than one sentence for context purposes
}
return reply ;
}
Aucun commentaire:
Enregistrer un commentaire