Crochet, java
Résolu/Fermé
maya 22
Messages postés
15
Date d'inscription
samedi 26 février 2011
Statut
Membre
Dernière intervention
23 mai 2011
-
Modifié par maya 22 le 16/04/2011 à 15:46
Utilisateur anonyme - 17 avril 2011 à 19:26
Utilisateur anonyme - 17 avril 2011 à 19:26
A voir également:
- Crochet, java
- Waptrick java football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Crochet clavier - Forum Bureautique
- Jeux java itel football - Télécharger - Jeux vidéo
- Bible java - Forum Téléchargement
3 réponses
Utilisateur anonyme
Modifié par danimo le 16/04/2011 à 21:15
Modifié par danimo le 16/04/2011 à 21:15
Bonjour,
On peut faire un peu plus simple:
Cordialement,
Dan
Ps,
Je vais essayer de voir pourquoi ton code ne donne pas le résultat escompté...
On peut faire un peu plus simple:
public class Crochets { private static String inputNew = ""; public static void main(String[] args) { String input= "pomme((carotte(radis)), chocolat(caramel))"; // Pour obtenir "pomme((carotte([radis])), chocolat([caramel]))" : String[] sentences = input.split(","); for(int i = 0; i <sentences.length; i++) { String str = sentences[i]; //System.out.println(">>>> str" + "\"" + sentences[i] + "\";"); int index1 = str.lastIndexOf("("); int index2 = str.indexOf(")"); if( (index1 > -1) || (index2 > -1) ) { inputNew+= str.substring(0, index1 +1) + ("[") + str.substring (index1 +1, index2) + ("]") + str.substring(index2) + (","); //System.out.println("inputNew = " + "\"" + inputNew + "\";"); } } inputNew = inputNew.substring(0,inputNew.length() -1); System.out.println("inputNew = " + "\"" + inputNew + "\";"); } }
Cordialement,
Dan
Ps,
Je vais essayer de voir pourquoi ton code ne donne pas le résultat escompté...
maya 22
Messages postés
15
Date d'inscription
samedi 26 février 2011
Statut
Membre
Dernière intervention
23 mai 2011
16 avril 2011 à 22:25
16 avril 2011 à 22:25
je vous remercie énormément pour votre aide Dan, votre code marche a merveille.
cordialement,
maya
cordialement,
maya
Utilisateur anonyme
Modifié par danimo le 17/04/2011 à 19:38
Modifié par danimo le 17/04/2011 à 19:38
Re,
Avec cette remarque importante:
Il faudrait ajouter un contrôle du format de la chaîne input.
D'autre part j'ai oublié ceci:
Cordialement,
Dan
Avec cette remarque importante:
Il faudrait ajouter un contrôle du format de la chaîne input.
D'autre part j'ai oublié ceci:
if( (index1 > -1) || (index2 > -1) ) { inputNew+= str.substring(0, index1 +1) + ("[") + str.substring (index1 +1, index2) + ("]") + str.substring(index2) + (","); //System.out.println("inputNew = " + "\"" + inputNew + "\";"); } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Ajouter : else { System.out.println("Erreur de format !!!"); return; } } ...... ..........
Cordialement,
Dan