473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Converting String to Integer

I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London
Jul 17 '05 #1
4 185910
Peter Warder wrote:
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London

int a = new Integer("123").intValue();

Jul 17 '05 #2
Joe
In article <Tm***************@news-binary.blueyonder.co.uk>,
pw*****@blueyonder.co.uk says...
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London

int i = Integer.parseInt("123"); // catch a NumberFormatException

Keep this URL handy:
http://java.sun.com/j2se/1.4.1/docs/api/

--
"Everybody plays the fool. Sometimes."
-- American Folk Saying
Jul 17 '05 #3
Thanks
Peter
"Joe" <sf***@spamcop.net> wrote in message
news:MP************************@sfo.news.speakeasy .net...
In article <Tm***************@news-binary.blueyonder.co.uk>,
pw*****@blueyonder.co.uk says...
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler won't have it!

What's the trick?

TIA

Peter / London

int i = Integer.parseInt("123"); // catch a NumberFormatException

Keep this URL handy:
http://java.sun.com/j2se/1.4.1/docs/api/

--
"Everybody plays the fool. Sometimes."
-- American Folk Saying

Jul 17 '05 #4
Thanks
Peter
"Boris Tabenkin" <le******@yahoo.com> wrote in message
news:GGLcb.430795$Oz4.229697@rwcrnsc54...
Peter Warder wrote:
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler won't have it!

What's the trick?

TIA

Peter / London

int a = new Integer("123").intValue();

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Fettig | last post by:
I have a quick simple question. How do you convert an integer to a string in Python? Thanks Ken Fettig
13
by: Gil | last post by:
I have a string : string A = "2"; I need to get it's integer value : // ?? int val = A ; // ??
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
0
by: wrytat | last post by:
In one web page, I redirect it to "prtDelReq.aspx?prtindex=0A2A3A8" after the user click the button. The prtindex actually contains many integers separated by 'A'. On the prtDelReq page, I use...
3
by: SiewSa | last post by:
I have come to a situation that I need to use the result of a string variable as a formula for performing calculation. As an example below: Dim X As Integer Dim Y As Integer Dim Result...
1
by: mdawoodk | last post by:
i am getting error "input string was not in correct format" when converting a string decimal into integer value. code is like this: string strVal = ""; int nVal = 0; strVal = "14.9"; nVal...
9
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string froma file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
1
by: sake | last post by:
This problem seems to have a fairly simple solution in C, and google seems to love to pull up solutions for C. However, C++ just seems have the exact opposite luck. So pretty much, I want to...
7
by: tragic54 | last post by:
Alright so i've done this in some of my recent programs with option strict on and for some reason When i debug and select the option from the combo box, it crashes and gives me a 'Input String was...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.