User Guide > Scripting > Using Scripts to Perform Specific Tasks > Parsing a Name Field Into Separate Fields
Was this helpful?
Parsing a Name Field Into Separate Fields
If a name field source data file contains parts of a name that you want to separate, use the NamePart Function to do the following:
Parse a name field into separate fields
Rearrange order of a name in the same field
Create a name part custom file
Prepare to parse the field by first doing the following:
Locate the source field that contains the data to be parsed.
Determine the number and position of the target fields needed.
Set up or select the fields in your target file to which the parsed data is written.
After you have completed the planning, write an expression to tell the map which portion of the parsed data goes into each target field.
Target Field Name
Target Expression
Honorific
= NamePart("h", FieldAt("/SOURCE/R1/Name"))
First Name
= NamePart("f", FieldAt("/SOURCE/R1/Name"))
Middle Name
= NamePart("m", FieldAt("/SOURCE/R1/Name"))
Middle Initial
= NamePart("mi", FieldAt("/SOURCE/R1/Name"))
Last Name
= NamePart("l", FieldAt("/SOURCE/R1/Name"))
Title
= NamePart("t", FieldAt("/SOURCE/R1/Name"))
In the example above, the source field that contains the full name is "Name". The fields in the target file that contain the name parts have been given field names that match the corresponding part of the name. The target expression in each of the fields has been written to instruct the map to place a specific name part in that field in the target data file.
Where "f" places the first names in the First Name field, "m" places the middle initial (or name) in the Middle Initial field, and "l" places the last name in the Last Name field, etc.
After the transformation is run, the names in every record are parsed into the separate fields in the target data file.
Example of Rearranging Order of a Name
There may be some instances where you need to reverse the order of the first and last names in a field that contains a full name. For example, the name appears in your source data file as Smith John, and you want the name to appear as John Smith in your target file.
You can write an expression for that field as follows.
Target Field Name
Target Expression
Name
= NamePart("f l", FieldAt("/SOURCE/R1/NAME"))
Where "NAME" is the field name in your source file that contains the person's name. And "f l" instructs the map to position the name in "firstname lastname" order in the Name field in your target file.
After the transformation is run, the names are in "firstname lastname" order in every record in your target data file.
Note:  Any string that is three or more characters in length and ends with a period can be considered an honorific.
See Also
Last modified date: 02/01/2024