Customer Portal

Splitting a field containing people's names

Comments 1

  • Avatar
    imriskal
    0
    Comment actions Permalink
    Hi Kevin,

    Here is my very simplified solution. I just assumed that the last space in a string is the delimiter. Everything before is the first name and everything after is the last name.
    $out.0.first_name = substring($in.0.full_name, 0, lastIndexOf($in.0.full_name, " "));
    $out.0.last_name = substring($in.0.full_name, lastIndexOf($in.0.full_name, " ")+1);

    However, I admit this is not a universally valid rule. If you have more complex definitions of first names and last names, you may find useful also split function. For instance:
    string[] names = split($in.0.full_name, " ");
    $out.0.first_name = names[0];
    $out.0.middle_name = names[1];
    $out.0.flast_name = names[2];

    Regards,

Please sign in to leave a comment.