Find/Replace

Hi to all I am trying to code Find/Replace with richTextBox. Can anyone help

Answer this question

Find/Replace

  • Knvb1123

    Thanks for help..
    Can we select all the occurance of search_string in RichTextBox.
    Is there any method or way to do that



  • WyattA

    hi,

    to find and replace in richtextbox you use the text property

    to repalce you do something like this

    rt.Text.Replace("oldvalue","newvalue");

    to find you may use something like this

    string value = "something";

    int start = rt.Text.IndexOf(value );

    rt.Select(start, value.Length);

    hope this helps



  • JoeCoder

    Hi I couldn't understand your reaction to that code. I mean if I need to find or replace don't I need a box to do like microsoft word have or I don't think I understand how does it work, since I am somehow new to C#.

    thanks jbattat


  • Tsuru

    shakalama wrote:

    hi,

    to find and replace in richtextbox you use the text property

    to repalce you do something like this

    rt.Text.Replace("oldvalue","newvalue");

    to find you may use something like this

    string value = "something";

    int start = rt.Text.IndexOf(value );

    rt.Select(start, value.Length);

    hope this helps



    If i want all the occurance of that text to be replaced then wat i have to do.

  • RajKS

    Hi Mr. Shakalama, I created a search form called searchForm and i am trying to use that as find and replace and serach, with this code :

    private void findToolStripMenuItem_Click(object sender, EventArgs e)

    {

    searchForm searchForm = new searchForm();

    richTextBoxPrintCtrl1.Find(searchForm.Show);

    searchForm.Show();

    }

    I am getting an error:

    Error 1 The best overloaded method match for 'System.Windows.Forms.RichTextBox.Find(string)' has some invalid arguments .

     

    Can you help

     

    Thanks jbattat


  • DTSlurve

    alwz_nikhil wrote:
    If i want all the occurance of that text to be replaced then wat i have to do.

    the code will replace all the occurance of the text

    hope this helps



  • Al Dynarski

    hi,

    i don't think exposing your form controls outsideof the form is a good thing, and you cant do it the way you did you can use constractors to do this, to add a constractor to your form that take a string and you write the find part in the search form you will instantiate the searchform like this

    SearchForm sf = new SearchForm("text to find");

    hope this helps



  • computer_guy

    You might want to look into regular expressions provided in System.Text.RegularExpressions.

  • Find/Replace