count number of occurrences in string c#

count number of occurrences in string c# 

 First use the following namesapce
          using System.Text.RegularExpressions; 

  Use the following Regx code to count 
           string source="one two three one two one" 
           int count = Regex.Matches(source, "\\b(" + Yourstring + ")\\b").Count;
  that "\\b(" is used for eliminate specal charcter.

No comments:

Post a Comment