I am retrieving a player-list from a server and I am doing stuff with it (un-related to problem) later on. These un-related processes only work if the username doesn't have spaces, but instead has the character '_'
instead of ' '
. I am using this code to loop through each playername's character and then detect if its a ' '
and, if it is, replace it with a '_'
but for some reason it doesn't get detected at all?
char[] name;
for(String playerName : chatlist) {
name = playerName.toCharArray();
for(int i =0; i < name.length; i++) {
if(name[i] == ' ') {
name[i] = '_';
}
}
String nameS = new String(name);
System.out.println(playerName + " -> " + nameS);
}
An example of a username and output is the following:
Testuser 1
would output Testuser_1
ExampleUser One
would output ExampleUser_One