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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| import java.util.ArrayList;
public class ChercheKeysTest2 {
public static void main(String[] args) {
String texte = "marque auto\n"+
"ff = {audi}_{bmw}_sylda_{peugeot}\n"+
"ee = {user}/{audi}/script/{audi}_{bmw}_sylda_{peugeot}/{Driver}/{mazerrati}/{Porche}/listing\n"+
"ff= {user}/{audi}/script/{audi}_{bmw}_sylda_{peugeot}/{Driver}/{mazerrati}/{Porche}/temoin\n"+
"ee = {user}/{audi}/script/{audi}_{bmw}_sylda_{peugeot}/{Driver}/{mazerrati}/{Porche}/results\n"+
"ff= {user}/{audi}/script/{audi}_{bmw}_sylda_{peugeot}/{Driver}/{mazerrati}/{Porche}/UCI_cree\n";
String VALUE_B ="{";
String VALUE_E = "}";
int ao = 0;
int po = 0;
ao = texte.indexOf(VALUE_B,po);
po = texte.indexOf(VALUE_E,ao);
while(ao >= 0 && po >= 0){
// ce qu'il y a entre { }
String a = texte.substring(ao+1, po);
//System.out.println(a);
// Ce qu'il y a avant {etude}
String b = texte.substring(0, ao);
//System.out.println(b);
// Ce qu'il y a après {etude}
String c = texte.substring(po+1,texte.length());
if (a != null) {
texte = b.concat(c);
po = po - (a.length()+2);
}
ao = texte.indexOf(VALUE_B,po);
po = texte.indexOf(VALUE_E,ao);
}
System.out.println(texte);
}
} |