charAt equivelant for Long?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: charAt equivelant for Long?

  1. #1
    Join Date
    Nov 2004
    Posts
    6

    charAt equivelant for Integer?

    i know how to use charAt for Strings, but I need to be able to identify an Integer by its first number, in other words I need to tell whether an int has either a 5 or a 1 as the first number for an if statement...any way to do this?
    Last edited by fixxxerkh; 03-15-2005 at 01:51 AM.

  2. #2
    Join Date
    Mar 2005
    Posts
    24
    seems like there's a way to do it with just devision.
    For example:
    the long we're looking at is 502314
    Code:
    long num = 502314;
    int i = 1;
    while (num / i > 10)
       i*=10;
    i = (int)(num/i);
    now i should be the first digit of the long, in this case, 5.
    I realize that's not quite as versatile as the charAt equivalent, but I think it should work. If not, you could always convert each digit into a char and store as a char array

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