1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
public String recherche(String chaine)
{
// String chaine = "bjkoknjkoiuytr";
//String cle = "bonjour";
String mot_trouver="";// initialisation
char[] tabChaine = chaine.toCharArray();
for(int i=0;i<mot.size();i++)
{
char[] tabCle = mot.get(i).toCharArray();
int indice = 0;
if (tabCle.length >=1)
{
if(tabCle[0] == tabChaine[0] && tabCle[tabCle.length-1] == tabChaine[tabChaine.length-1])
{
indice = 1;//On commence par la seconde lettre
for(int j=0;j<tabChaine.length;j++)
{
if(indice >= tabCle.length-1) //On finit par l'avant dernière lettre
{
break;
}
if(tabChaine[j] == tabCle[indice])
{
indice++;
}
}
}
if(indice >= tabCle.length-1)//Mot trouvé?
{
mot_trouver=tabCle.toString();
break;
//System.out.println("\""+cle +"\" est dans la chaine :"+chaine);
}
else
{
System.out.println("\""+mot_trouver +"\" n'est pas dans la chaine :"+chaine);
}
}
}
return mot.get(mot.indexOf(mot_trouver));
} |