I wish to extract the numerical part of a text in string and convert it to int. For example, consider the following text :
1-16 of 310 results for "phone case"
Normally, I could use
String total_item_str = search_result.substring(8,10);
to extract the value 310. However, that is if it is consistently 3 digits.
My issue is since this is returning the total search result and it can any number of digits, how do handle this dynamically ? Meaning, I wish to be able to extract the total search result from the text no matter how many digits it returns.
String numberofResults = string.substring(string.indexOf("of")+2, string.indexOf("result")).trim();and then just parse that String to an Integer.