What is the best way to extract the integer part of a string like
Hello123
How do you get the 123 part. You can sort of hack it using Java’s Scanner, is there a better way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Why don’t you just use a Regular Expression to match the part of the string that you want?
That’s all you need, plus whatever surrounding chars it requires.
Look at http://www.regular-expressions.info/tutorial.html to understand how Regular expressions work.
Edit: I’d like to say that Regex may be a little overboard for this example, if indeed the code that the other submitter posted works… but I’d still recommend learning Regex’s in general, for they are very powerful, and will come in handy more than I’d like to admit (after waiting several years before giving them a shot).