In our work in HotDocs, we often need to bring in defective and malformed data from databases. Often the data source contains an address field or fields. Ideally, it will be formatted with Street, City, State and Zip as separate fields. However, more often, the data is not properly structured for analysis and usage. We may get address line 1 and address line 2 or even address line 3. To put this data into a usable format requires an understanding of text parsing.
With the use of the Custom Functions properties of HotDocs Computations, we have defined a way to parse the Address Line text which is in the [CityName], [StateAbbrev] [ZipCode] format in a line into the 3 separate constituent fields, respectively tmpCity, tmpState, and tmpZip. We pass a parameter, prmCSZ which contains the address string. The output sets the tmp fields which can then be used in a dialog script or other computation to set the actual fields you wish to use.
We make extensive use of local variables.
- Store the address string (city, state zip) in locCSV
- Trim locCSV to remove extra spaces found in the database
- Extract Zip and set locZip
- We need to test for a hyphen to determine the length of the Zip Code
- If there is a hyphen, then we take the last 10 characters and then purge from locCSV
- If there is no hyphen, we take the last 5 characters.
- Extract the City
- We look for the last comma as a delimiter
- We set locCity to anything before the comma
- Extract the State
- The state is everything that is left
- We need to trim the leading and following spaces
- What is left is either an abbreviation or the full state name.
- Depending on your target format, you convert to full state name or to abbreviation
Good luck with the computation and be sure to come back to this site for other useful tips. If you need any special help, click on Support or call us for a consultation.