How can i find out of Number of occurances in string?I have used array to find out.Is there any other way (Use of IndexOf) to find out?
s = "Apple"; //No of occurances of 'p'string
char[] c = s.ToCharArray();
int count = 0;
for(int i=0;i { if (c[i] = = 'p') { count++; } } Console.Write(count); Thanks.
AlanPosted Aug 7, 2007, 3:55 PM
It's difficult to find anything comprehensive, apart from the MSDN documentation itself, but these two tutorials are not bad and cover the main methods and properties of the String class:
http://www.csharphelp.com/archives4/archive702.html
http://en.csharp-online.net/Manipulating_Strings_in_CSharp
jaguRitaPosted Aug 7, 2007, 3:20 PM
AlanPosted Aug 7, 2007, 3:09 PM
Here's another way:
string s = "Apple";
int count = s.Split('p').Length - 1;