A paragraph contain number of statements.The program is to find that how many times a particular word present in the paragraph...(without using any special method)
EX:consider its a pragraph :
wwwwwwwwwwww red wwwwwwwwwred ....sabdkjab red jhhkshhkhk red hkhkhhgiuyvvu red...
Find how many times the word red present in this paragraph...
Loading

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 17, 2013, 8:16 PM EDT
Try like this
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 17, 2013, 8:33 PM EDT
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main(string[] args)
{
string test = "wwwwwwwwwwww red wwwwwwwwwred ....sabdkjab red jhhkshhkhk red hkhkhhgiuyvvu red...";
string searchItem = "red";
int count = new Regex(searchItem).Matches(test).Count;
Console.WriteLine("No of occurence:" + count);
Console.ReadLine();
}
}
output: No of occurence: 5
for more details:
http://www.dotnetperls.com/string-occurrence
http://www.dotnetperls.com/word-count
VulpesRank #55 · 29.2K reputationPosted Jul 18, 2013, 12:40 AM EDT
int count = new Regex(@"\b" + searchItem + @"\b").Matches(test).Count;
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 18, 2013, 1:05 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 18, 2013, 1:08 AM EDT
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 18, 2013, 1:22 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 18, 2013, 1:51 AM EDT
int count = new Regex(searchItem).Matches(test).Count;
Ravi ShekharRank #673 · 3.6K reputationPosted Jul 18, 2013, 1:59 AM EDT
Riyaz AkhtarRank #2,275 · 619 reputationPosted Jul 18, 2013, 2:05 AM EDT
see below code:
check below link for more details:
http://msdn.microsoft.com/en-us/library/bb546166.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
vasanth krishna41 reputationPosted Jul 18, 2013, 4:53 AM EDT
vasanth krishna41 reputationPosted Jul 18, 2013, 4:56 AM EDT