开发者

Replacing multiple items in rich text box

开发者 https://www.devze.com 2023-04-02 02:27 出处:网络
I am trying to change multiple items in a richtextbox. When I run my code the only item thats changed is the first

I am trying to change multiple items in a richtextbox. When I run my code the only item thats changed is the first

try
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    while (!reader.EndOfStream)
                    {
                       richTextBox1.AppendText(reader.ReadLine());
                         richTextBox1.Rtf = richTextBox1.Rtf.Replace(t开发者_开发问答extBox1.Text, textBox2.Text);
                    richTextBox1.Rtf = richTextBox1.Rtf.Replace(textBox3.Text, textBox4.Text);
                    richTextBox1.Rtf = richTextBox1.Rtf.Replace(textBox5.Text, textBox6.Text);

                    }

                }

               // using (StreamWriter writer = new StreamWriter(path))
              //  {

              //  }
            }


I also think your way to loop in the StreamReader is not optimal, usually it's handle like this:

    using (StreamReader sr = new StreamReader("TestFile.txt"))
    {
        String line;
        // Read and display lines from the file until the end of
        // the file is reached.
        while ((line = sr.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号