2011-11-20 4 views

Répondre

2

Vous pouvez utiliser la méthode indexOf de la classe chaîne:

String haystack = "the red cat is watching the red car stopped at the red stop sign"; 
String needle = "red"; 
int idx = 0, pos; 
while((pos = haystack.indexOf(needle,idx)) != -1) { 
     System.out.println(pos+1); 
     idx += pos+1;  
} 

See it

+0

Merci de m'avoir aidé à trouver les aiguilles perdues! ;-) – SliverNinja

Questions connexes