Hi is there any way to parse strings into numbers? And is there any way to check if a string is a number or not without breaking the program ? I am thinking about using a try and catch would this be a good idea ?
Share
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.
There’s no way to check if a string is parseable or not without trying to parse the string (as any check would have to start trying to interpret the string as a number to do that…). For a half-way check, I guess you could use Regex to check if the string has only digits and periods. You’ll have to use a try… catch block aswell, though.
As to how to parse a string into a double, try this: