Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:58:43+00:00 2026-06-03T07:58:43+00:00

I want to make a find and a find & replace function for my

  • 0

I want to make a find and a find & replace function for my RichTextBox. So far I’ve found out that the .Find() function comes in quite handy, but I can’t think of a good way to let it skip to the next word in the textbox.

So far I have this:

BeginIndex = txtDocument.Find(str, BeginIndex + WordLength, RichTextBoxFinds.None);
WordLength = str.Length;

BeginIndex is a variable that is public and starts out as 0, same as WordLength. This way it will start looking at the first character, and the next time it won’t find the same one.
There is a big malfunction though, let me try to describe it:
“Hello blablab hello blablaal balbalbla hello blabla” If I would look for “hello” in this sentence, it will select the first hello, then the second, then the third, then the third again. After that it will just find the second and the third over and over. Because WordLength is still > 0.

So I need a new way to tell the Find() method that its not allowed to find the one already found, but move on, and when the last one is found, go back to the first. Is there a more clean and better way to do this?

Edit: Its almost fixed, I use this now:

BeginIndex = txtDocument.Find(str, BeginIndex, RichTextBoxFinds.None);

if(BeginIndex == -1) {
    BeginIndex = 0;
    SearchString(str, heelwoord, casesensitive);
}

BeginIndex += str.Length;

Now, this loops quite nice, instead of calling itself (int the if) I can also make a MessageBox that says something like “End is reached!”. But if it finds nothing, it gives me an error. I use the function with 2 checkboxes, one that does MatchCase, and one that does WholeWord, but when I look for ‘a’ in “asdasdasd” and check WholeWord, it errors because its unfindable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:58:44+00:00Added an answer on June 3, 2026 at 7:58 am

    You might be better off implementing Knuth-Morris Pratt’s algorithm, it might be faster than the internal .NET solution and it will allow you to know exactly where the strings are found. You can do substring concatenation magic afterwards, assign the result to the rtf’s text and you’ll be all set.

    http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make tests in a constructor to find out if it is
I couldn't find any article that would help me. I want to make an
I want to find or make a bookmarklet that will validate the html content
i want to find values in array according to alphabate and want to make
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
I can't seem to find an answer on this and just want to make
I am using SlimDX with WinForms for a while now, but want to make
I want to make a bigger checkbox in WPF. I've discovered that I need
I want to have one model & view that is served by multiple controllers
So i'm trying to make a program that can find how many pixels of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.