Comparaison de string en Java

Résolu
Utilisateur anonyme -  
 danimo -
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
Configuration: Windows XP
Firefox 2.0.0.13

3 réponses

  1. Necriptos Messages postés 30 Statut Membre 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
  2. danimo
     
    salut,

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

    Cordialement,

    Dan.
    1