String tokeniser

D

Director

I have a problem, can someone please tell me how to go about splitting
a query of the following type:
And(dog, Or(mouse,cat));
into:
dog
or(mouse,cat)

I can manage to split it to
dog, Or(mouse,cat)
but if i use string tokeniser with ',' as the delimiter it would split
it into:
dog
or(mouse
cat)

can someone tell me a way around the problem?
 
A

antroy

Director said:
I have a problem, can someone please tell me how to go about splitting
a query of the following type:
And(dog, Or(mouse,cat));
into:
dog
or(mouse,cat)
...
can someone tell me a way around the problem?

Not using a StringTokenizer, no. That's for fairly trivial tokenizing.

If the query is always of the form And(..., Or(...,...)); then Reg exe's
are probably the way forward with the String replaceFirst(String find,
String replace) method.

The find regex should be something like:
"And\\((.+?),\\s*O(r\\(.+?\\))\\)" and the replace String should be
"$1\no$2"

If this is just an example of a more general query, then you'll probably
have to write a dedicated parse method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top