我如何.MatchCase和.WholeWord?MatchCase、WholeWord

2023-09-04 05:02:47 作者:卜够成熟¢

我一直都做一个查找,查找下一个功能,我的richtextbox,所以让由整个单词或区分大小写或两者的用户搜索我的这些复选框,然后我拿到了前两个,工作,但我不能得到它与这两个情况下,整个单词检查工作,这是我的code:

Ive been making a find, find next function for my richtextbox, so I have these check boxes to let the user search by whole word or case sensitive or both, and I got the first two, to work but I can't get it to work with both case a whole word checked, here's my code:

if (isWhole == true && isCase == true)
            {
                string searchText = Form2.text;
                this.Focus();
                richTextBox1.Focus();
                findPos = richTextBox1.Find(searchText,findPos,richTextBox1.Text.Length, RichTextBoxFinds.WhatGoesHere?);

                richTextBox1.Select(findPos, searchText.Length);
                findPos += searchText.Length;
            }

不过,有一个为wholeword没有选择和matchcase那么有没有什么办法与.Find()?

But there's no option for wholeword and matchcase so is there any way to do this with .Find()?

推荐答案

的的 RichTextBoxFinds 是一个'标志'枚举,这意味着你可以'或'的值加在一起:

The RichTextBoxFinds is a 'flags' enum, meaning you can 'or' the values together:

findPos = richTextBox1.Find(searchText,findPos,richTextBox1.Text.Length,
   RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
相关推荐