Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Extracting a char from a string in java

  • 09-05-2007 07: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, Registered Users 2 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