How do I .MatchCase and .WholeWord?

五迷三道 提交于 2019-12-08 05:22:55

问题


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;
            }

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


回答1:


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);


来源:https://stackoverflow.com/questions/2865615/how-do-i-matchcase-and-wholeword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!