Solved

Convert specified character in a String to an int

Posted on 2004-08-03
4
316 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 50
servlet example 11 50
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 22
Bot application - advice 3 39
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

820 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