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
|
import java.util.*;
import java.awt.*;
public class Requetes{
public static void main(String[] args) {
ArrayList<String> array = new ArrayList<String>();
ArrayList<Point> indices = new ArrayList<Point>();
String expr = "test(\"1234\").insert(<ma balise> <secondeone>(coucou) </secondeone></mabalise>)";
String exprTemp = expr;
//debut de la méthode
int temp1 = exprTemp.lastIndexOf("(");
int temp2;
while(temp1>0) {
System.out.println(temp1);
temp2 = exprTemp.indexOf(")",temp1);
if (indices.size()>0) {
for (int j=0; j< indices.size();j++) {
if ( temp1 < indices.get(j).x && temp2 > indices.get(j).y ) {
indices.remove(j);
array.remove(j);
}
}
}
array.add(expr.substring(temp1+1,temp2));
indices.add(new Point(temp1,temp2));
exprTemp = exprTemp.substring(0,temp1) + " " + exprTemp.substring(temp1+1,temp2) + " " + exprTemp.substring(temp2+1,expr.length());
temp1 = exprTemp.lastIndexOf("(");
}
//fin de la methode
for (int i=0;i<array.size();i++) {
System.out.println(array.get(i));
}
}
} |