Converting String to Integer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Warder

    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


  • Boris Tabenkin

    #2
    Re: Converting String to Integer

    Peter Warder wrote:
    [color=blue]
    > 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
    >
    >[/color]
    int a = new Integer("123"). intValue();

    Comment

    • Joe

      #3
      Re: Converting String to Integer

      In article <TmIcb.632$yd5. 126@news-binary.blueyond er.co.uk>,
      pwarder@blueyon der.co.uk says...[color=blue]
      > 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
      >
      >
      >[/color]


      int i = Integer.parseIn t("123"); // catch a NumberFormatExc eption

      Keep this URL handy:


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

      Comment

      • Peter Warder

        #4
        Re: Converting String to Integer

        Thanks
        Peter
        "Joe" <sfjoe@spamcop. net> wrote in message
        news:MPG.19dd36 421f58208e98984 1@sfo.news.spea keasy.net...[color=blue]
        > In article <TmIcb.632$yd5. 126@news-binary.blueyond er.co.uk>,
        > pwarder@blueyon der.co.uk says...[color=green]
        > > 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[/color][/color]
        compiler[color=blue][color=green]
        > > won't have it!
        > >
        > > What's the trick?
        > >
        > > TIA
        > >
        > > Peter / London
        > >
        > >
        > >[/color]
        >
        >
        > int i = Integer.parseIn t("123"); // catch a NumberFormatExc eption
        >
        > Keep this URL handy:
        > http://java.sun.com/j2se/1.4.1/docs/api/
        >
        > --
        > "Everybody plays the fool. Sometimes."
        > -- American Folk Saying[/color]


        Comment

        • Peter Warder

          #5
          Re: Converting String to Integer

          Thanks
          Peter
          "Boris Tabenkin" <leetree1@yahoo .com> wrote in message
          news:GGLcb.4307 95$Oz4.229697@r wcrnsc54...[color=blue]
          > Peter Warder wrote:
          >[color=green]
          > > 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[/color][/color]
          compiler[color=blue][color=green]
          > > won't have it!
          > >
          > > What's the trick?
          > >
          > > TIA
          > >
          > > Peter / London
          > >
          > >[/color]
          > int a = new Integer("123"). intValue();
          >[/color]


          Comment

          Working...