Solved

Convert specified character in a String to an int

Posted on 2004-08-03
4
289 Views
Last Modified: 2010-03-31
I have a String composed of a series of numbers and need to get an int value of the number, i.e., convert "7" to 7.  Figured out how to do it, am wondering if there is a simpler way.

String theInput = "5678";
int intTemp = Integer.parseInt(String.valueOf(theInput.charAt(2)));

gives me intTemp = 7;

Thanks.
0
Comment
Question by:dancebert
  • 4
4 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
int intTemp = Integer.parseInt(String.valueOf(""+theInput.charAt(2)));
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
Also
int intTemp = Integer.parseInt(theInput.charAt(2));
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
Comment Utility

Also
int intTemp = Integer.parseInt(""+theInput.charAt(2));
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility

Also
int intTemp =(int)theInput.charAt(2)-(int)'0';
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now