Convert String to char or check if String contains only numbers
Hello,
I have been given a programming assignment, which i believe is not properly thought through.
In a string i have some numbers:
String cpr = "1234"
Now, i must test the this string contains only numbers. It is suggested that i use Character.isDigit() to check it, but then i would need to convert the string to an char - and i havent found any easy ways of doing this. Are there any other methods of testing if a string consists of only numbers??
I was also told to implement a toString method which is never used. Now, what i think is that, cpr should be a Character, and then i would use toString to convert it to string when needed, but.....not according to the teacher
Re: Convert String to char or check if String contains only numbers
Re: Convert String to char or check if String contains only numbers
Please mark the thread resolved from the "Thread Tools" menu in the top of this form so others would know your problem has been resolved.
And by the way, try "Regular Expressions" if you can. they serve best in such cases