Fullname replace comma - place it in the beginning

Hi, any suggestion, how to solve this issue:

Fullname results: Miller, Reto

Trying to display it like that: Reto Miller

  • Remove the comma and put it in the beginning

Already started but was only able to remove the comma… thank you

<cfset fullname = rereplace( fullname , ',(?=[^,]+$)' , '' ) />
<cfoutput>#fullname #</cfoutput>

Jquery solution: 
   jQuery(function($) {
   $(".name").text(function(i, t) {
   return t.split(/,|\s/).reverse().join(" ");

One possible solution could be

<cfset fullname="Miller, Reto" />
<cfset fullname = "#trim(listlast(fullname,","))# #trim(listfirst(fullname,","))#"/>

1 Like
    fullname="Miller, Reto";
    echo(fullname.ListToArray().reverse().toList(" "));
1 Like

@Retooo: Zacs post is, if you want to transcript your jquery/javascript to CFML the more accurate answer. That is exactly why I love CFML that much: You have different ways in CFML to whatever you want… Do you have more experience with dot.notated functions in script? Or do you like to use cf-tags? And if you want to do the best of both, doing cfml islands in Lucee is a great way, just like ben nadel posted recently in this forum and his blog. And there is even more possible in Lucee. CFML in Lucee is real fun!

1 Like

I mainly go that approach to avoid repeated list functions, obviously in this case it’s doesn’t make much difference performance wise, but any time you work with a (longer) list, it’s going to perform better if you just create an array and then work with the array, otherwise, the list gets reparsed over and over again

1 Like

Thank you for your support
scenarios are working fine !

Thank you for your support, scenario are working fine

yes it is!!! thank you always for your great advices

1 Like

I’m not a Lucee developer, but I saw this topic and thought I’d share the solution that I use when it comes to parsing names, I’ve had success using these two (2) java libraries:

I’ve also used this javascript version on the client-side to provide Microsoft Outlook-like name parsing from a single input field.

1 Like

Here’s the test suite of name strings that I use when parsing & normalizing names.