Comparaison de string en Java

Résolu
Utilisateur anonyme -  
 Utilisateur anonyme -
Bonjour,


je voudrais savoir comment peux ton comparer deux string an JAVA pour savoir si la seconde string est présente dans la première..


merci
A voir également:

3 réponses

kilian Messages postés 8732 Date d'inscription   Statut Modérateur Dernière intervention   1 526
 
5
Necriptos Messages postés 29 Date d'inscription   Statut Membre Dernière intervention   9
 
Salut,



    String string = "comment ça marche ?";
    String cherche = "marche";
    
    // recherche de la chaine "cherche" dans la chaine "string" :


     index = string.lastIndexOf(cherche);  // 11

    //  index renvoie la position de la chaine cherche dans la chaine string, si non présente index renvoie -1



Cordialement,

Necriptos
2
Utilisateur anonyme
 
salut,

Il faut lire : ...., si non présente index renvoie -1

Cordialement,

Dan.
1