472,362 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,362 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 185806
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.