Skip to content

Instantly share code, notes, and snippets.

@virendersran01
Forked from muthuraj57/ShortName.java
Created July 11, 2020 11:30
Show Gist options
  • Save virendersran01/4c8da8d6e3ceba03c3dfb2087a9da040 to your computer and use it in GitHub Desktop.
Save virendersran01/4c8da8d6e3ceba03c3dfb2087a9da040 to your computer and use it in GitHub Desktop.
/*
* Return user short name
* */
public static String getShortName(String name) {
String[] strings = name.split(" ");//no i18n
String shortName;
if (strings.length == 1) {
shortName = strings[0].substring(0, 2);
} else {
shortName = strings[0].substring(0, 1) + strings[1].substring(0, 1);
}
return shortName.toUpperCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment