|
-
Oct 3rd, 2007, 05:57 AM
#1
Thread Starter
Addicted Member
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
-
Oct 3rd, 2007, 09:32 AM
#2
Thread Starter
Addicted Member
Re: Convert String to char or check if String contains only numbers
-
Oct 3rd, 2007, 05:18 PM
#3
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|