Forum Discussion
SteveFlowers
11 years agoCommunity Member
Yep. This should work. Looks for the last space. If the last space is the next to last character, strip it off. Otherwise, keep it.
var LMSName="flowers, steve t";
if(LMSName.lastIndexOf(" ")==LMSName.length-2){
//has an initial
LMSName=LMSName.substring(0,LMSName.length-2).split(",");
nameOut=LMSName[1]+" "+LMSName[0];
}else{
//no initial
LMSName=LMSName.split(",");
nameOut=LMSName[1]+" "+LMSName[0];
}
document.write(nameOut);