I’m working on a Java class that gets parameters from an “Account Request” form (like ‘First Name’, ‘Last Name’, ’email’, etc.).
The Java class first gets the parameters from the form. It then initializes a user name with the first and last name strings like so:
String userName = firstName.substring(0,1).toLowerCase() + lastName.toLowerCase();
For example, the username for “Jake Smith” would be jsmith.
Afterwards, it checks to see if this ‘userName’ exists in the database. Obviously, “Jake Smith” and “John Smith” would create identical user names, “jsmith”. To account for this, I’d just like to append numbers, starting with 1, to any matching user names.
How can I append a unique number at the end of each and every conflicting username (starting with 1 and incremented by 1 for each additional conflict)?
Obviously, a more elegant solution would be to allow the user to specify their user name, but this is how the mock client wants the project to be completed.
Thank you!
A “dumb” solution, but if it’s just for tests…
Considering that
userNamedon’t have digits in the end.