Results 1 to 3 of 3

Thread: Convert String to char or check if String contains only numbers

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: Convert String to char or check if String contains only numbers

    solved

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
  •  



Click Here to Expand Forum to Full Width