"**" to be delimiter!! not only "*" what can I do!!???for StringTokenizer

In my work
If I have an equation, a+b**c+d*e
** means exponent. so b^c (but I should do that way **)
there are 5different operators ---> ** + - / *
so...I'm trying to use StringTokenizer.
such that,
StringTokenizer st = new StringTokenizer(String, "*/+-", true)
even if I make (String,"*/+-**", true) ,it does not work.
Is there any way I can do that??
please somebody help me....

As the StringTokenizer API doc says: All characters in the delim argument are the delimiters for separating tokens
In other words, only single characters are used as separators.
You might consider using Pattern and Matcher.
For example:        String input = "a+b**c+d*e";
        Pattern pattern = Pattern.compile("[+\\-/]|\\*{1,2}|\\w+");
        Matcher matcher = pattern.matcher(input);
        while(matcher.find()) {
            System.out.println(matcher.group());
        }

Similar Messages

Maybe you are looking for