Marcelo Bordolli wrote:i need to grab a Sting like this: "1-25" or one like this "3 selected" and parse it into an int. just the numbers like for the first i need an int = 1 25 or similar; and for the second int = 3;
I've tried doing:
Integer foo = Integer.parseInt("3 selected");
but of course its not working
Can someone advise thanks!!
Basically, the easiest way to find numbers in a string is to use regular expressions... see the java.util.regex.Pattern class. Unfortunately, if you don't know regular expressions, it is probably not a good idea to use it -- although, I do highly recommend that you learn it.
Without regular expression, you can loop through the string looking for the characters (that are digits), and then use the substring() method to extract the numbers to be parsed into a int.