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 '' 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); }   

An example of a user name and output is as follows:

TestSyear 1 output Testuser_1

Example user output ExampleUser_One

Use Replacement All ("\\ s +", "_") . The better way to do this is, otherwise you will change each location with "_" (is it what you want?)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -