String Manipulation Task
I have a String of the following form.
"Some Text (Some Integer)"
How do I extract only the number part within the brackets? A sample code would be appreciated.
"Tom Cruise (125)"
"Mel Gibson (10)"
First find the index of '(' and ')' signs, other words first and last occurrence of them within the string.
then find the substring using calculated values
String ss = "Tom Cruise (125)";
// First occurrence of '('
int firstIndex = ss.indexOf('('); // gives a value
// Last occurrence of ')'
int lastIndex = ss.indexOf(')'); // or you can use lastIndexOf()
Hope it helps to you.
String subSt = ss.substring((firstIndex + 1), (lastIndex - 1));