This function receives a person’s name and inverts the first and last names.
It will insert a comma after the last name if it is reverted.
Example: “John C. Doe” becomes “Doe, John C.” and “Doe, Jane K.” becomes “Jane K. Doe”
Argument: sName (required), name to be converted

Author: Ricardo Parente
Date: Oct 16 2000
function rpSwapNames(sName){
var firstName = "";
var lastName = "";
var delim = " ";
var result = arguments.sName;
if (listLen(arguments.sName, delim) lt 2) return result;
if (find(",", arguments.sName)) {
delim = ",";
arguments.reverted = true;
firstName = listLast(arguments.sName, delim);
lastName = reverse(listrest(reverse(arguments.sName), delim));
return firstName & iif(arguments.reverted, de(""), de(",")) & " " & lastName;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.