Search code examples
c#searchuser-interfacedirection

How to search words in richtextbox with different orders(up and down)?


Like I want to search 'test' from the beginning of the sentence or the end of the sentence, how to make it work? What method should i use? I will type "test" in a textbox, and search in the richtextbox, the sentence is in richtextbox. Thank you for taking your time.


Solution

  • You can use System.Text.RegularExpressions.Regex.IsMatch() to check for certain text string in a larger text string:

    if (System.Text.RegularExpressions.Regex.IsMatch("text string including test", "test", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
    {
        //test found
    }
    

    Hope this helps