I want to split a String in Android using Java. I have done this before but now I get this exception
11-20 17:57:37.665: ERROR/AndroidRuntime(25423): java.util.regex.PatternSyntaxException: Syntax error U_REGEX_MISMATCHED_PAREN near index 1:
11-20 17:57:37.665: ERROR/AndroidRuntime(25423): (
11-20 17:57:37.665: ERROR/AndroidRuntime(25423): ^
My string is like
String mystring= "iamhere(32)";
and I want to keep only the "iamhere".
I split it using
String[] seperation = mystring.Split("(");
What am I doing wrong?
("\(") would be an invalid escape sequence. To escape the meaning of "(" we should be using "\\" in java.
String mystring = "iamhere(32)";
String[] sep = mystring.split("\\(");
System.out.println("String after split ",sep[0]+" ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With