473,386 Members | 1,694 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,386 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 185911
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.