String to Integer

How to convert a string variable to integer variable without using Integer.parseInt() fuction
aeltechAsked:
Who is Participating?
 
objectsCommented:
Loop thru the characters from last to first
for each character convert it to a number,  int n = (int) c - '0'
and mutlipy it by a multiplier which is initially 1, and add the result to your result value
for every loop, multipy the multiplier by 10

let me know if u get stuick :)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Use valueOf () ;-)

Oops, this has been asked before:

http://forum.java.sun.com/thread.jspa?threadID=675339&messageID=3943530
0
 
Mayank SAssociate Director - Product EngineeringCommented:
That is somebody's homework done.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
objectsCommented:
> Aks him how many of his  comments I deleted

Not that many that I can recall :) But some yes.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
He he he he.... there is a reason why objects did not post full-code. You think him or I couldn't have written it ;-) ?
0
 
WebstormCommented:
Hi aeltech,

See link posted by mayankeagle:
value=0;
for each digit : value=value*10+(digit-'0');

And if you have signed values, check if first character is '+' or '-' or digit, if '-' then return -value
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.