solomon mwika

solomon mwika

  • 1.2k
  • 210
  • 7.9k

Reading a text file

Jan 26 2014 3:17 AM
am trying to read  random words from a textfile . well have managed to read the words and display them in textblock problem is i only need to read words of certain
 
length only for example 5 to ten letters only
 
here is my code so far
 
private void Mywords()
{

var ResourceStream = Application.GetResourceStream(new Uri("TextFile1.txt", UriKind.Relative));
using (Stream Myfilestream = ResourceStream.Stream)
{
string s = "";
StreamReader myStreamReader = new StreamReader(Myfilestream);
s = myStreamReader.ReadToEnd();

s = s.Trim(); //tlbRandomWords.Text = s; // char[] delimiters = { '\n', '\r' };

string[] words = s.Split(); // int index = rand.Next(0,delimiters.Count());
if (s.Split().Length < 6)
{

tlbRandomWords.Text = words[rand.Next(words.Count())].ToUpper();
}
}

Answers (7)