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

Extracting a char from a string in java

Options
  • 09-05-2007 7:42am
    #1
    Closed Accounts Posts: 29


    Hi All,

    I would imagine that this is fairly straight foward but what I am tryin to do is compare two strings and depending on the outcome change the value in one string to the character value in another string

    This is the code I am trying
    if (number[i].charAt(0) != node.charAt(0))
       {
    
        //Hope to replace node with the first char in number[i]
    
       node = number[i].substring(0);
    
       System.out.print(node);
    
       }
    
    But for input such as 34 for number, when I print out node it is also 34. I have tired replace and changing the types to char arrays and then back again and it just falls over.

    Any suggestions would be great.


Comments

  • Registered Users Posts: 37,485 ✭✭✭✭Khannie


    So....for input of 34, you want node to hold 3? Is that right?

    If so...node = number.substring(0,0);


Advertisement