Solved

Convert specified character in a String to an int

Posted on 2004-08-03
4
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

752 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