I’m trying take the names that I am given by the program after it retrieves them from unstructured text, and display them in a user specified Format of either “First MI. Last” or “Last, First MI”. Any ideas? So far it checks to see if a comma is present in the string. if so I want to switch the order of the words in the string and remove the comma, and if there is a middle initial and it doesnt’ contain a period after it, I want to add one.
if (entity instanceof Entity) {
// if so, cast it to a variable
Entity ent = (Entity) entity;
SName name = ent.getName();
String nameStr = name.getString();
String newName = "";
// Now you have the name to mess with
// NOW, this is where i need help
if (choiceStr.equals("First MI. Last")) {
String formattedName = WordUtils
.capitalizeFully(nameStr);
for (int i = 0; i < formattedName.length(); i++) {
if (formattedName.charAt(i) != ',') {
newName += formattedName.charAt(i);
}
}
}
name.setString(newName);
network.updateConcept(ent);
Use a regular expression and
String.replaceAll:The result is
Barack H. Obama.