Find/Replace function RichTextBox
<p>I want to make a find and a find &amp; 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.</p>

<p>So far I have this:</p>

<pre><code>BeginIndex = txtDocument.Find(str, BeginIndex + WordLength, RichTextBoxFinds.None);
WordLength = str.Length;
</code></pre>

<p>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.</p>

<p>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?</p>

<p>Edit: Its almost fixed, I use this now:</p>

<pre><code>BeginIndex = txtDocument.Find(str, BeginIndex, RichTextBoxFinds.None);

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

BeginIndex += str.Length;
</code></pre>

<p>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.</p>
