DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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 12: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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links