package javaapplication1;
import java.io.IOException;
public class JavaApplication1 {
public static void main(String[] args) throws IOException {
try {
String s = "abc abc abc bc";
int pos = 0, count = 0;
while ((pos = s.indexOf("bc", pos)) != -1) {
System.out.println(pos);
System.out.println(s.substring(pos));
pos++;
count++;
}
if (count > 0)
System.out.println("found total of: " + count + " instances");
else
System.out.println("not found");
} catch (Exception e) {
System.out.print(e.toString());
}
}
}
/*
run:
1
bc abc abc bc
5
bc abc bc
9
bc bc
12
bc
found total of: 4 instances
*/