Les expressions régulières en java
Bonjour je me tourne vous voir encore une fois espérant trouver une solution, voici d’abord mon code que j’écris en ce moment :
Code:
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
|
if (TXT.contains("toto")
&& TXT.contains("titi")) {
String alpha = TXT.substring(TXT
.indexOf("toto"), TXT.indexOf(
titi, (TXT.indexOf("toto")))); /* ici j'extrais un bout de chaine de mon texte */
pattern = Pattern.compile("\\W");
/* Separation in sub-string's */
String[] items = pattern.split(TXT, 12);
/* Parcours table of sub-string's */
for (int i = 0; i < items.length; i++) {
}
String CH = (items[10]); /* L'entier ici me gène */
TXT = TXT.replace(alpha, "ma nouvelle " + CH
+ "\n");
}else log("Invalid line. Unable to process.");
/** Iterate in this part ! */
if (TXT.contains("tutu")) {
String beta = TXT.substring(TXT.indexOf("tutu"), TXT
.indexOf(" ", (TXT.indexOf("tutu"))));
TXT = TXT.replace(beta,
"une nouvelle ligne");
}else log("Invalid line. Unable to process."); |
Tout d’abord es que vous savez si c’est possible par un string (indexOf(String)) par exemple String CH = (items[indexOf(String)+1]);
Mon deuxième problème es que vous pouvez m’indiquez, vu que j’ai plusieurs tutu dans mon texte comment le changer à chaque fois par beta, car la j’ai que le premier tutu qui est changé.
Merci pour toute réponse
Cordialement