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?

Edited 4 Years Ago by J_A_L: n/a

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.

This question has already been answered. Start a new discussion instead.