zanko360 1 Share Posted January 3, 2019 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 More sharing options...
zanko360 1 Author Share Posted January 4, 2019 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 More sharing options...
ozeki6 32 Share Posted January 4, 2019 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 More sharing options...
zanko360 1 Author Share Posted January 4, 2019 @ 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 More sharing options...
ozeki6 32 Share Posted January 5, 2019 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.