Comparaison de string en Java

Résolu/Fermé
Utilisateur anonyme - 26 mars 2008 à 20:55
 Utilisateur anonyme - 27 mars 2008 à 09:36
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 vendredi 19 septembre 2003 Statut Modérateur Dernière intervention 5 février 2025 1 526
26 mars 2008 à 21:01
5
Necriptos Messages postés 29 Date d'inscription mercredi 26 mars 2008 Statut Membre Dernière intervention 8 juillet 2009 9
26 mars 2008 à 21:06
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
27 mars 2008 à 09:36
salut,

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

Cordialement,

Dan.
1