!!! Continuing code implementation
Continuing the implementation of the code, version 4.6.6.6, let's program the retrieval of the city and state when we have case 1, where the separator between the city and state in the original address string is a dash. The logic here is straightforward: if it's a dash, we'll apply a split operation using the dash as the delimiter, with the city at position 1 and the state at position 2. It's important to use the trim function to remove any extra spaces that might accompany the city or state names.
Inside the if statement for case 1, create a string array variable named vArray and set it equal to the result of splitting the address using the dash as the delimiter. This array will have three positions: the address at position 0, the city at position 1, and the state at position 2.
Next, check the type parameter. If it's "city," return the trimmed value from position 1 of vArray. If it's "state," return the trimmed value from position 2 of vArray.
Now, let's implement the logic for case 2. Here, we'll split the string by the dash first and then split the resulting city and state pair by a comma. Depending on the type parameter, return either the city (if "city") or the state (if "state").
Moving on to case 3, if neither a dash nor a comma is found as a separator, we'll assume a default scenario where the city and state are separated by a space. In this case, we'll split the string by the dash, take the second element of the split (which contains the city and state together), and then use the substring function to extract either the city or the state based on the type parameter.
Remember to trim any leading or trailing spaces from the extracted city or state names.
Once the implementation is complete, test the function with various scenarios, including addresses separated by a dash, a comma, and spaces.
After testing, save the final version of the function.
In the next video, we'll use this function in a transformation. Thank you, and see you in the next video!