Jump to content

getPlayers filter name with spaces


Recommended Posts

Posted (edited)
getPlayers().filter(p -> p.getName().toLowerCase().equals("nospace"));

This works fine - the player if found if they're nearby.

getPlayers().filter(p -> p.getName().toLowerCase().equals("name with space"));

This seems to work randomly - some names work and others don't. Does anyone have any idea why that could be?

Edited by Ragnar Lothbrok
Posted (edited)
21 minutes ago, Ragnar Lothbrok said:

Why would some names be like this and not others - doesn't make much sense but I'll give it a go thanks!

Cause \u00a0 is a non breaking space, as in if its at the end of the line it blocks the text editor from breaking the word. In other words, non breaking space is counted as a part of the word.

Also it should be username.replaceAll("\\u00a0", " ") because you need to escape the back slash.

Edited by Vilius
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...