Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
there is two textboxes. in first textbox you enter a string and another you enter a substring. you have to find total matching substring in first string and count them.
Posted

1 solution

use Regex

C#
int count = Regex.Matches( string1,  string2 ).Count;
 
Share this answer
 
Comments
prashbari 29-Jun-14 1:08am    
which namespace is used for Regex?
DamithSL 29-Jun-14 3:03am    
System.Text.RegularExpressions
prashbari 5-Jul-14 1:18am    
This is correct for primary condition ie only for count. But if i have to count with two conditions as-
1)Case(upper case and lower case)
2)With white spaces remove.
Please tell me how to solve this....
DamithSL 5-Jul-14 1:45am    
you can use Trim to remove leading and trailing spaces and also convert both input and pattern to lower case or upper case will do case intensive count
Regex.Matches( string1.ToLower(), string2.Trim.ToLower()).Count;
prashbari 5-Jul-14 2:58am    
i use this solution but still it's not working. Is there any solution for this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900