I am trying to extract only 2882649 from a string automation130214141113 (order # 2882649).
Can anyone help me out?
I am trying to extract only 2882649 from a string automation130214141113 (order # 2882649).
Can anyone help me out?
I'm not sure if you want a more dynamic solution for this, more context would help. But the following will parse the string down to just "2882649" as a string:
String str = "automation130214141113 (order # 2882649)";
String[] splitStr = str.split(" ");
String result = splitStr[3].substring(0, splitStr[3].length() - 1);
This is not the most elegant way to do this but you'll notice if you print result it will be the string "2882649".
Welcome to SO. Here is the simple approach.
String rawText = "automation130214141113 (order # 2882649)";
String number = rawText.substring(s.indexOf("# ") + 1).substring(0, s.indexOf(")"));
System.out.println(number);
To extract the sub-string 2882649 from the string automation130214141113 (order # 2882649) the easiest way would be to use multiple delimiters the #
and the )
character and you can use the following solution:
Code Block:
String MyString = "automation130214141113 (order # 2882649)";
String[] SplitString = MyString.split("# |\\)");
System.out.println(SplitString[1]);
Console Output:
2882649