jeudi 20 juillet 2017

Remove pattern from string in Java

I am currently working on a tool, which helps me to analyse a constantly growing String, that can look like this s="AAAAAAABBCCCDDABQ" What I want to do is to find a sequence of A's and B's, do something and then remove that sequence from the original String.

My code looks something like this:

while (I don't know){

if(Pattern.matches("A+B+", string))){
//Do stuff
//Remove the found pattern
}

if(Pattern.matches("C+D+", string))){
//Do other stuff
//Remove the found pattern
}

}

What I also don't know is how I could remove the three sequences, so that s just contains Q at the end of the calculation, without and endless loop. It is probably very easy but I am to tired right know. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire