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 HussainPosted Jul 18, 2013, 12:16 AM
Try like this
Regards,
Iftikar
vasanth krishnaPosted Jul 18, 2013, 8:56 AM
vasanth krishnaPosted Jul 18, 2013, 8:53 AM
Riyaz AkhtarPosted Jul 18, 2013, 6:05 AM
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
Ravi ShekharPosted Jul 18, 2013, 5:59 AM
VulpesPosted Jul 18, 2013, 5:51 AM
int count = new Regex(searchItem).Matches(test).Count;
Ravi ShekharPosted Jul 18, 2013, 5:22 AM
Sanjeeb LenkaPosted Jul 18, 2013, 5:08 AM
Ravi ShekharPosted Jul 18, 2013, 5:05 AM
VulpesPosted Jul 18, 2013, 4:40 AM
int count = new Regex(@"\b" + searchItem + @"\b").Matches(test).Count;
Sanjeeb LenkaPosted Jul 18, 2013, 12:33 AM
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