Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Convert specified character in a String to an int

Posted on 2004-08-03
Medium Priority
336 Views
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
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
• 4

LVL 14

Expert Comment

ID: 11706590
int intTemp = Integer.parseInt(String.valueOf(""+theInput.charAt(2)));
0

LVL 14

Expert Comment

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

LVL 14

Accepted Solution

sudhakar_koundinya earned 200 total points
ID: 11706605

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

LVL 14

Expert Comment

ID: 11706618

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

## Featured Post

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 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 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…
###### Suggested Courses
Course of the Month9 days, 14 hours left to enroll