Hello,
I want to know how I can split a String variable by the square brackets (open and close) as delimeters. Here's my SSCCE. The problem is that I don't know how to make the square brackets seem as literal variables and not what they're normally used for in regular expressions. When I use a backslash before each square bracket, I get compile errors becuz they are the wrong escape characters.
Also, I eventually need to display the result of this split as a String array. Is there a way to do this?
Please help me out. Thanks!
public class MyStringTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "[A, B, C]";
String [] splittedStr = str.split("[|]");
for(int i=0;i<splittedStr.length;i++)
{
System.out.println(splittedStr);
}
System.out.println(splittedStr);
}
}