how to find string in a text file c# code example
Example: how to find string in a text file c#
private void button1_Click(object sender, EventArgs e) { string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt"); while ((line = file.ReadLine()) != null) { Console.WriteLine(line); string[] lineStrings = line.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries); if (lineStrings.Length > 2) { if (lineStrings[0] == txt1.Text) { txt2.Text = lineStrings[1]; txt3.Text = lineStrings[2]; return; } } } file.Close(); // Suspend the screen. Console.ReadLine(); }