-4

I am trying to extract only 2882649 from a string automation130214141113 (order # 2882649).

Can anyone help me out?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ruhan
  • 1
  • 1

3 Answers3

0

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".

KunduK
  • 32,888
  • 5
  • 17
  • 41
C. Peck
  • 3,641
  • 3
  • 19
  • 36
0

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);
supputuri
  • 13,644
  • 2
  • 21
  • 39
0

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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352