Re: urgent pls - to find the numberof occurences in a string

Listserver <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <[email protected]>
Hope this will help


public  int PatternCount(String substring, String source)
  {

   if ((substring ==null) || (source == null))
    return  -1;

   if ((substring.Length ==0) || (source.Length ==0))
    return  0;


   int count = 0;
   for(int i = 0; i < source.Length && ((i =
source.IndexOf(substring,i,source.Length-i)) != -1);i += substring.Length,
count++)
    ;
   return count;

  }
  public  int WordCount(String substring, String source)
  {
   if ((substring ==null) || (source == null))
    return  -1;

   if ((substring.Length ==0) || (source.Length ==0))
    return  0;

   char[] whitespaces = {' ','\n','\r','\t'};
   String[]string_array = source.Split(whitespaces);
   int count = 0;
   foreach( String stringitem in string_array)
   {
    if (substring.CompareTo(stringitem)==0) count++;
   }

   return count;
  }
----- Original Message -----
From: "george antony" <[email protected]>
To: <[email protected]>
Sent: Sunday, June 16, 2002 10:18 AM
Subject: [DOTNET] urgent pls - to find the numberof occurences in a string


> hi
> Can any one tell me How to find the no of times a
> particular word is repleated in a string in .net..
> regards
> gan
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.