A=0, B=1 ....


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: A=0, B=1 ....

  1. #1
    Join Date
    May 2005
    Posts
    115

    A=0, B=1 ....

    Let's say i have a String "ABCD"

    How do i code it so that when i pass this string into a method, it'll process A as 0, B as 1, C as 2 and D as 3?

    In other words, when "ABCD" is passed into the method, i want to operate on 0123, when ACDB, 0231 and so on...

    Thx guys...

    (If it's possible, i would like to avoid using switch-case)

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    A-Z uppercase range from 10 to 35, independent of the Unicode specification. (from the Character class API)

    Code:
            String stuff = "ACDB";
            
            for(int i=0; i<stuff.length();i++)
            {
                char c = stuff.charAt(i);
                int value = Character.getNumericValue(c)-10;
                System.out.println(c+" = "+value);
            }

  3. #3
    Join Date
    May 2005
    Posts
    115
    Thx Phaelax..got it

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