java - Returning a formatted string does not working properly -


i have created dupe-check makes sure newly created usernames unique.

it looks this:

string p1 = <code>; //first 3 chars in first name string p2 = <code>; //first 3 chars in last name int p3 = 1;         //unique identifier. boolean dupecheck;  {   dupecheck = false;   (int = 0; < usernamelist.size(); i++) {     if (usernamelist.get(i).equals(p1+p2+integer.tostring(p3))) {       dupecheck = true;       p3++;     }   } } while (dupecheck == true); 

this works, if return:

return string.format("%s%s%d", p1, p2, p3); 

duplicate usernames names like:

  • xxxyyy1
  • xxxyyy2
  • xxxyyy3

which great. want unique identifier (p3) allways 3 digits long. string.format comes play, along problems.

if return following code:

return string.format("%s%s%03d", p1, p2, p3); 

for reason, dupe check fails , these usernames:

  • xxxyyy001
  • xxxyyy001
  • xxxyyy001

can explain happening?

if store usernames using %03d, i.e. leading zeros, should use when compare string in usernamelist:

usernamelist.get(i).equals(string.format("%s%s%03d", p1, p2, p3)) 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -