Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

casting char[] to int in java

Options
  • 29-10-2008 9:39pm
    #1
    Closed Accounts Posts: 34


    say I have some stuff in a char array data[] and data = 7. I want to add data to an int or change data into an int so I can add it, but I keep getting the ASCII table value 55.

    I've tried int x = (int)data but that didn't work. This is bugging me now because I'm sure its something simple I've just become confused looking at all the int to char tutorials but can't seem to find a char[] to int one. Anyone got any ideas or pointers ?


Comments

  • Closed Accounts Posts: 34 jackofnotrades


    Got it ... had to make it into a string first, If anyone has an easier way I wouldn't mind seeing it !

    String strChar2Int = String.valueOf(data);
    x = Integer.parseInt(strChar2Int);


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Don't know if this works but have you tried
    stringByte = String.valueOf(data[i]);
    int x    = Integer.parseInt(stringByte);
    

    Edit: Ok you just got there before me!


Advertisement