vendredi 20 février 2015

occurrences and order of substrings in a string java

I have a string that contains a lot stuffs, and I want to parse it and get the occurrences of the strings "sat" and "unsat" in the correct order. basically, the input is a string (see below) and the output would be and List where if I find "sat" I will put 1 and if "unsat" 0.





sat
(= abst1ring1 true)
(= availablering3 false)
(= intermring4 false)
(= availablering5 false)
(= availablering2 false)


unsat

sat
(= intermring5 false)
(= intermring2 false)
(= abstring5 true)
(= abstring2 true)
(= available1ring1 false)
(= interm1ring1 false)
(= abstring3 true)
(= availablering4 false)
(= abstring4 true)
(= intermring3 false)
(= htokenring2 3)
(= htokenring5 3)
(= htoken4 3)
(= htrigger1ring1 3)
(= htoken3 3)
(= htokenring3 3)
(= x5 3)
(= htoken1 3)
(= htoken1ring1 3)
(= x2 3)

unsat

unsat



Here the output that I am looking for would be: [1,0,1,0,0].


Especially knowing that "sat" is also a substring of "unsat", which causes a problem too.


I tried to use Pattern and Matcher classes in java but I am having ordering problems? Any idea on how can I do it in a clean way? I am not looking for the code but just a proper way to do it


Many thanks, Cheers


Aucun commentaire:

Enregistrer un commentaire