How can I do a split of = in Java [closed]

0

I need to split from a given string according to a series of comparison symbols.

I am using this sentence:

String[] partes = condicion.toString().split("<|>|=|<=|>=|or|and|not");

The problem is that with <, > = or and y not it does it well and there are no problems, but with <= y >= it does not take them well and it leaves me blank.

Any ideas on how to split so that I take the two symbols?

Thanks

    
asked by OnlyDavies 21.06.2018 в 11:24
source

1 answer

2

You can use a regular expression for the first part <|>|=|<=|>=

String[] partes = condicion.toString().split("[<>]=?|=|or|and|not");

The first part [<>]=? searches for any character < , > , and followed by 0 or 1 occurrence (the ? behind the same serves for this) of the character = , therefore contemplate <, > <=, y >=

As an example:

String condicion= "0<1>=2or3<=4or5and6<7=hola";

String[] partes = condicion.toString().split("[<>]=?|=|or|and|not");
for (String parte : partes) {
    System.out.println(parte);
}
    
answered by 21.06.2018 / 13:08
source