http://www.dotnetperls.com/string-occurrence
Simple aproach
string haystack ="/once/upon/a/time";
string needle ="/";
int needleCount =( haystack.Length- source.Replace(needle,"").Length)/ needle.Length
If you're using .NET 3.5 you can do this in a one-liner with LINQ:
int count = source.Count(f => f =='yourSearchChar');
If you don't want to use LINQ you can do it with:
int count = source.Split('yourSearchChar').Length-1;
Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif
Sangeetha Mani, if this helps please login to Mark As Answer. | Alert Moderator