Off With the Head! 22/100 Days of Code
Another feature down. Now the program can remove an address from the list.
Start
As I mentioned previously, when the zip code is in the first address in the list, the program uses the indexOf method to find the first comma in the list. All characters that come before this comma are what make up the first address.
The program then creates a substring of this address before updating the list. The new list is created using a substring from two characters after the end of the address to the end of the original list. This ensures the new list does not begin with a whitespace or a comma. (see below)
End
When the address containing the zip code is at the end of the list, the program uses the lastIndexOf method to find the last comma in the list. This comma should come right before the last address. The program then obtains the address by taking a substring from after the comma to the end of the list.
The list is updated with a substring from the start of the original list to the character two indexes before the start of the address. This is to ensure the new list ends before the comma, keeping with the proper csv format.
Middle
Now, the program handles middle addresses a little differently. When the address containing the zip code is in the middle of the list, the program finds it and creates a substring from the beginning to the zip code.
After that, the program creates two new substrings from the original list. The first substring is from the beginning of the list to two characters before the address. The second substring is from the comma after the address to the end of the list.
The updated list combines both “halves” of the original list, leaving out the address containing the zip code.
The newly added feature allows the program to update the value of the list with a new String. Next, it needs to obtain the street information from the address.