Solved

Convert specified character in a String to an int

Posted on 2004-08-03
4
297 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
ID: 11706590
int intTemp = Integer.parseInt(String.valueOf(""+theInput.charAt(2)));
0
 
LVL 14

Expert Comment

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

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
ID: 11706605

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

Expert Comment

by:sudhakar_koundinya
ID: 11706618

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what is the difference between "sudo su" and "su - root" 6 102
Cipher Configuration on Apache HTTPD 4 50
how to add new optional parameter to JSP 1 26
tomcat not starting 6 26
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

914 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

21 Experts available now in Live!

Get 1:1 Help Now