I Have string in the form
var dummyString = $@"SIGNED APPLICATION AND AFFIDAVIT REQUIRED LOCATION: BLK 99, LOT 9 AND BLK 100 LOT 9, 10, 11, 12 & 13 RT 38 EAST HAINESPORT, NJ BASED ON: VACANT LAND";
What I would like to do is to extract the location/address from this string. I can easily find the index of the LOCATION: but can't think of of efficient solution for the index where i should terminate the string. The easiest option is to iterate over the list and find the index of a state code but this won't be very efficient way of handling it.
What i thought would be the solution to this problem is to use a list of US state codes and then find the index of the first match of any state code after the index of LOCATION: substring with a whitespace so I can find the complete state code and its index.
public const List<string> USStateCodes = new List<string> { "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY" };
Any idea on how to proceed from here?
The output i want is:
BLK 99, LOT 9 AND BLK 100 LOT 9, 10, 11, 12 & 13 RT 38 EAST HAINESPORT, NJ
The problem stated here is part of bigger logic where I use regex to find the index of zip code (5 digits) as terminator but in some cases, the zip code may not be present in address (user error). I still have to be able to extract the address.
SIGNED APPLICATION AND AFFIDAVIT REQUIRED LOCATION:andBASED ON: VACANT LANDremain same always in the input string?