torquish Posted August 10, 2019 Posted August 10, 2019 (edited) I am trying to get a Player's object from the specified name. What I have currently only works when the name doesn't contain a space. What am I doing wrong? private Player getPlayerObjectFromName(String name) { List<Player> players = getPlayers().filter(player -> player != null && player.getName().equalsIgnoreCase(name)); if (players != null) { for (Player p : players) { if (p.getName().equalsIgnoreCase(name)) { return p; } } } return null; } Edit: So I figured out the issue. Player objects use (char) 160 as a space which is why I was never getting a match when testing a name with (char) 32 as its space. Edited August 10, 2019 by torquish
Token Posted August 10, 2019 Posted August 10, 2019 23 minutes ago, torquish said: I am trying to get a Player's object from the specified name. What I have currently only works when the name doesn't contain a space. What am I doing wrong? private Player getPlayerObjectFromName(String name) { return getPlayers().closest(player -> player.getName().replaceAll(“\\h”, “ “).equalsIgnoreCase(name)); } Edit: So I figured out the issue. Player objects use (char) 160 as a space which is why I was never getting a match when testing a name with (char) 32 as its space. Can’t check if that works as I’m on phone atm, but the idea is those weird characters should be in java’s horizontal whitespace character class, but not in the general whitespace class \s. P.S. Replace the double quote characters, I don’t have that on iphone keyboard 1
torquish Posted August 10, 2019 Author Posted August 10, 2019 4 minutes ago, Token said: Can’t check if that works as I’m on phone atm, but the idea is those weird characters should be in java’s horizontal whitespace character class, but not in the general whitespace class \s. P.S. Replace the double quote characters, I don’t have that on iphone keyboard Yes it works. Thanks.