Parsing


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Parsing

  1. #1
    Join Date
    Jul 2004
    Posts
    83

    Parsing

    How can I parse a get a char from a string, say i'm reading each letter from a string using substring (String a=line.substring(x,x+1);
    //reads one letter at a time
    how can i get that one letter to a char?
    then from a char to an int?
    They say if you play a Microsoft Windows CD backwards it will play satanic messages. But thats nothing, if you play it forwards it installs Windows.

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    don't use substring, you're overcomplicating the issue. The String class has a method called toCharArray(), which not surprisingly returns and array of chars which is exactly what you want. You can then loop through the array to get the various characters.

    To turn a char into an int you have to cast it. Something like int myInt = (int)myChar.

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    If you cast it, wont that return the ascii value of the char? He may be asking for the numerical value, in which cause the command (i think) is:
    Integer.parseInt()

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    well try them both and see which gives the result you want

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center