Prepare For Output--Parse Zipcode

The following code is used to split zip codes from a pattern match. The code below takes a zip code and assigns the first five digits to the variable "ZIP". If the zip code is in the longer format (12345-6789), as opposed to the shorter format (12345), then the second part of the zip code, which comes after the "-" character, is assigned to the "ZIP4" variable (so named for the 4 digits following the "-" character). This script would be useful in cases where zip codes must be standardized.

 try{<br />
    // Local reference to variables<br />
    String zip = dataRecord.get("ZIP");<br />
<br />
    if(zip != null){<br />
        // Split the zip code on the "-" character (for zip codes in the 12345-6789 format)<br />
        String[]  zipParts = zip.split("-");<br />
  <br />
         // Put parts in dataRecord<br />
        dataRecord.put("ZIP", zipParts[0]);<br />
  <br />
         // If we were able to split the zip into two pieces (for zip codes in the 12345-6789 format),<br />
        // then we store the last four digits in the variable "ZIP4"<br />
        if (zipParts.length == 2){<br />
            dataRecord.put("ZIP4", zipParts[1]);<br />
        }<br />
    }<br />
}<br />
<br />
catch(Exception e){<br />
    session.log("Error running Fix Zip Codes and Nulls");<br />
}