User Guide : Scripting : Using Scripts to Perform Specific Tasks : Parsing a Source Field by Character
Share this page             
Parsing a Source Field by Character
Sometimes you want to parse data in a field that is not name or address data. The Parse function allows the user to parse one source field into two or more target fields by a particular character or characters in the source field.
Some common characters to parse by are: a space, "," (comma), "*" (asterisk), or "/" (slash). However, any printable character can be used to parse the data. So, if you parse by a character that is part of the actual data, you may get undesirable results.
To prepare for parsing, make sure you do the following:
Locate the source field in the map that contains the data to be parsed.
Determine which character you will use to parse the data.
Map the target fields to which the parsed data is written.
Now, write an expression in each mapped target field that detects the character and then writes the correct portion of data to that field.
The following scenario illustrate how you may use the Parse function to parse the data in one source field into two separate fields in your target file.
A Customer field in your source file contains a region code (ABC), an '*' (asterisk), and a customer number (10019). For example: ABC*10019. The region code and customer code are always separated by an * but each code could be more than three to five letters. In your target file, you want the region code to be in one field called REGION, and the customer number in another field called CUSTOMER NO.
Insert an additional field in the desired position within the map. Then, write a target field expression in each of the two fields to instruct the map to parse the data and place each "section" of the parsed data in that field in the target data file.
Target Field Name
Target Field Expression
= Parse(1, FieldAt("/SOURCE/R1/Customer"), "*")
Customer No
= Parse(2, FieldAt("/SOURCE/R1/Customer"), "*")
The data in the "Customer" field in the source file is being parsed on the "*" (asterisk). The "1" in the top expression places the first "section" of the parsed data in the Region field, and the "2" in the bottom expression places the second "section" of the parsed data in the Customer No field in the target data file.
If you need to parse a field on more than one character, the syntax is as follows:
Parse(number, "string", "char1", "char2", ...).