Problem using java String.split() method

Hi all, I have a problem regarding the usage of java regular expressions. I want to use the String.split() method to tokenize a string of text. Now the problem is that the delimiter which is to be used is determined only at runtime and it can itself be a string, and may contain the characters like *, ?, + etc. which are treated as regular expression constructs.

Is there a way to tell the regular expression that it should not treat certain characters as quantifiers but the whole string should be treated as a delimiter? I know one solution is to use the StringTokenizer class but it's a legacy class & its use is not recommended in Javadocs. So, does there exist a way to get the above functionality using regular expressions.

Please do respond if anyone has any idea. Thanx

Hamid

[814 byte] By [mianhamid82@yahoo.coma] at [2007-10-2 3:17:47]
# 1
Can you escape them? put "\\" infront of each char ...
prob.not.sola at 2007-7-15 21:45:09 > top of Java-index,Java Essentials,Java Programming...
# 2

For example:public class Splitty {

public static void main(String[] args){

String delim = "\\\\\\*\\?";

String message = "aaa\\*?bbbb\\*?ccc\\?*ddd";

String[] splat = message.split(delim);

for(int k = 0; k < splat.length; k++){

System.out.println(k + ": " + splat[k]);

}

}

}

prob.not.sola at 2007-7-15 21:45:09 > top of Java-index,Java Essentials,Java Programming...
# 3

Check the Javadoc for the Pattern class. In particular look at

\Q Nothing, but quotes all characters until \E

\E Nothing, but ends quoting started by \Q

These will allow you to split on anything with little or no regard for what you are splitting on.

The only 'gotya' is that if the thing you are looking for contains \E you will have to escape it!

sabre150a at 2007-7-15 21:45:09 > top of Java-index,Java Essentials,Java Programming...