Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert specified character in a String to an int

Posted on 2004-08-03
4
Medium Priority
?
340 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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 …
Suggested Courses

824 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