• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

String to Integer

How to convert a string variable to integer variable without using Integer.parseInt() fuction
0
aeltech
Asked:
aeltech
  • 3
  • 2
2 Solutions
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now