Clara Duta

Clara Duta

  • NA
  • 1
  • 1.2k

Highlight words in multiple files

Aug 17 2012 1:16 PM
Hey everyone. What I want to do and don't know how is to find and highlight these 2 words "game" and "player" in .txt files. 
No richtext. 
so mostly like this code: 
  private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Filter =
                "TEXT (*.xml;*.txt|";
            this.openFileDialog1.Multiselect = true;
            this.openFileDialog1.Title = "My text editor";
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
                foreach (String file in openFileDialog1.FileNames)
                    try
                    {
                        StreamReader reader = new StreamReader(file);
                        string content = reader.ReadToEnd();
                        reader.Close();
                        content = Regex.Replace(content, "game", "gaming"); 
content = Regex.Replace(content, "player", "playing"); 

so mostly like this code, but not actually replacing the word, just find it and highlight it. Help ???

Answers (1)