0

Hey everyone,
how do i find and highlight a specific word in a .txt file?
I only have this until now :
this.openFileDialog1.Filter = "TEXT (.xml;.txt|";
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "My text editor";
DialogResult dr = openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
and i want to find these two words : "game" and "player" within a .txt file and highlight them if they're found.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by clarisaduta
0

i already checked them out. i dont want to have a richtext. i want to have an openfiledialog that opens files (.txt) and finds and highlights the words game and player. so highlighting only these two words "game" and "player" in multiple files.

0
  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", "punt");                 

basically what this code does but not replace it, only highlights the word "game".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.