Hi everybody.

I'm trying to split a string such that every array element would have characters between open and close prentesis.
mmm let me just show:

myString = "(2*((3-2)+(5-3)))"

So my array should have values like that:
myArray[0] = 2*((3-2)+(5-3));
myArray[1] = (3-2)+(5-3);
myArray[2] = (3-2);
myArray[3] = (5-3);

I tryed to do that by using .split() but

Here is my code and output:

public class P2 {
    public static void main(String[] args) {
	new P2();
    }
    public P2() {
	String myString = "(2*((3-2)+(5-3)))";
	String myArray[] = myString.split("\\(");
	for(int i=(myArray.length-1); i>=0; i--) 
	    System.out.println("myArray["+i+"] : "+ myArray[i]);
	}
}
myArray[4] : 5-3)))
myArray[3] : 3-2)+
myArray[2] : 
myArray[1] : 2*
myArray[0] :

I don't know if a regexp will do that. Perhaps someone that knows will come along and suggest a solution.

You might be able to use the String class's indexOf and substring methods.

Hmmm I changed your split method to account for either bracket.

myString.split("[\\(||\\)]");

Is this what you were looking for?

Hmmm I changed your split method to account for either bracket.

myString.split("[\\(||//)]");

Is this what you were looking for?

YEAS!!!!!!
EXACTLY!!!!
thanks a lot!!!! really appreciate it!

YEAS!!!!!!
EXACTLY!!!!
thanks a lot!!!! really appreciate it!

Ah good! Glad to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.