We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to count the occurrence of a word in Text?

Hi, there. How to count the occurrence of a word in Text? I read a old post about this issue, but the suggested solution is not applicable anymore since Find method is removed from release 4.1.0.10 which is what I am using. FindText(...) returns a boolean value, but FindNext() retuns nothing. Another similar question is how to find out how many words are replaced when ReplaceAll() is called? This method returns nothing. Thanks. Feng Chen feng.chen@hrblock.com

1 Reply

AD Administrator Syncfusion Team January 18, 2006 11:26 PM UTC

Hi Feng, You could find the number of occurences of any string in the EditControl using the following code : Regex r = new Regex(searchText, RegexOptions.IgnoreCase); MatchCollection ma = r.Matches(this.editControl1.Text); return ma.Count; I have attached a test sample here that illustrates the same. Please refer to it and let me know if this meets your requirements. We have also considered adding a GetInstanceCount method to the EditControl that returns the number of occurences of the specified string. We will try our very best to implement this feature request and you could track the progress of the same at this link below : Feature Request #694 - Support for GetInstanceCount method in the EditControl Thanks for your interest in Essential Edit. Regards, Guru Patwal Syncfusion, Inc.

Loader.
Live Chat Icon For mobile
Up arrow icon