Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Comparing strings with spaces


    zanko360

    Recommended Posts

    Greetings,

    I have a problem with comparing 2 names. One got with grandChild.getText() the other friend.getName(). The thing is the comparison returns FALSE if both names are the same but have spaces in them. If there are no spaces in the names it works fine. This is the code:

    if(vars.gChildM.getText().contentEquals(vars.addedPlayers.get(vars.iterator).getName())) {

    so:

    if(grandChild.getText().contentEquals(listOfFriendObjects.get(indexOfList).getName())) {

    Checking with .equals() also doesn't work

    Link to comment
    Share on other sites

    Also doing .hashCode on the 2 strings brings different value, on the strings with no space in it, results in same value. Hope this helps

    Link to comment
    Share on other sites

    19 hours ago, zanko360 said:

    Also doing .hashCode on the 2 strings brings different value, on the strings with no space in it, results in same value. Hope this helps

    Try to log both objects. If they have the same exact output then I would conclude that they are different objects (they aren't both Strings). If that's the case then you have to cast one of them to String. However, I may be wrong.

    Link to comment
    Share on other sites

    @

    ozeki6

     

    I have debugged this for 6h believe me probably even more. No the objects are both strings it is a bad api method. Have tried EVERYTHING, in the end all the analysing and changing of my code was for nothing as I figured out that the space you get from widget.getText() is not actually a space but a "non-breaking space" 160 unicode not 32 LOL?? And java does not take this 2 as the same so comparing the same name got from 2 different places looked the same in console output but actualy is 2 different characters. Check this I posted in Errors & bugs

     

    Link to comment
    Share on other sites

    3 hours ago, zanko360 said:

    @

    ozeki6

     

    I have debugged this for 6h believe me probably even more. No the objects are both strings it is a bad api method. Have tried EVERYTHING, in the end all the analysing and changing of my code was for nothing as I figured out that the space you get from widget.getText() is not actually a space but a "non-breaking space" 160 unicode not 32 LOL?? And java does not take this 2 as the same so comparing the same name got from 2 different places looked the same in console output but actualy is 2 different characters. Check this I posted in Errors & bugs

     

    Yes, I got it. I was going to suggest that but I thought that it's both unlikely and stupid to suggest. 

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.