-4

I have made replace function, but I am really struggling to make "Replace All" function. I tried to make into for loop but that didn't work well... I have dialog box just like in usual Notepad (another form) and i have richtextbox in Main form. Any ideas how can I make it?

kristy889
  • 1
  • 1

1 Answers1

4

You can simply use the String.Replace method:

private void DoReplace(string SearchFor, string ReplaceWith)
{
    RichTextBox1.Text = RichTextBox1.Text.Replace(SearchFor, ReplaceWith);
}

Call this function and supply the string you want to search for in Richtextbox1 (or whatever it is called in your case) as the first parameter and the replacement as the second parameter.

Jens
  • 6,275
  • 2
  • 25
  • 51