check no of occurence
Program-
Write a java program to find out the number of times a
substring occurs within the string
class Search
{
public static void main(String args[
])
{
String s=new String("this is a
this is a this is a that");
String p=new String(args[0]);
int count=0;
int position=0;
while(position=s.indexOf(p,position)!=-1)
{ count++;
position=position+p.length();
}
System.out.println("Total
Occurances ="+count);
}
}
Comments
Post a Comment