the code below will pull a matched word from a text file and display the line it matched something on. It will even display 3 lines that matched the same word.
but what I really want to do is to take the line with the most matches so if textbox1.text was entered "How would I learn c sharp the fastest" than it would take the whole sentence into account and then display the most accurate line with the most matches from the text file.
private void button1_Click(object sender, EventArgs e)
{
int counter = 0; string line;
StringBuilder sb = new StringBuilder();
// Read the file and display it line by line.
using (System.IO.StreamReader file = new System.IO.StreamReader("C:\\TextFile1.txt"))
{
while ((line = file.ReadLine()) != null)
{
if (line.Contains(textBox1.Text))
{
// append the text and a newline into the StringBuilder buffer
sb.AppendLine(line.ToString());
}
}
}
textBox2.Text = sb.ToString();
}
}
}

New Topic/Question
Reply




MultiQuote





|