java - Convert spaces to underscores -
I am retrieving a player list from a server and I'm doing stuff with it (later problem related to) . These un-related processes work only if the user name does not have an empty space, but instead of An example of a user name and output is as follows: Use '' the character is
'_' I am using this code for loop through character and then find it a
'' and, if it is, then it will be replaced with
'_' Change, but for some reason it is not known at all?
four [] names; (String player name: chatlist) {name = playerName.toCharArray (); For (int i = 0; i & lt; name.length; i ++) {if (name [i] == '') {name [i] = '_'; }} String name S = new string (name); System.out.println (player name + "->" + nameS); }
TestSyear 1 output
Testuser_1
Example user output
ExampleUser_One
Replacement All ("\\ s +", "_") . The better way to do this is, otherwise you will change each location with "_" (is it what you want?)
Comments
Post a Comment