Update:
Now I just need help extracting the State from an address field.
I want it to work for the following addresses:
183 Holly St., Hollywood, CA 92545
408 Tree St., Cherry Hill, New Jersey 22545
So in other words I need it to work for when state and cities can be two words.
//State
Trim(Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s").FullMatch,", ",""))
The above code for state doesn't work all the time. It doesn't work when the city is two words. The state name captures part of the city name then. Otherwise it's correct. So I tried the following pattern to include digits at the end using Regex, but I need to figure out how to take out the digit at the end afterwards. I am not the best at Regex and strings.
Substitute(Match(TextInput3_17Address.Text,",\s*([A-Za-z\s]+)\s\d").FullMatch,", ","")
This produces, like "CA 2" the state, plus the first digit. Does anyone know how I can take off the last character? After that I will just use the Trim() function to get rid of the space.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original Post:
I want the default property of a new field to have conditional logic that incorporates parts of a shipping address.
So if the field value (DataCardValue158) is "No" then will be "TextName" with City/State of the shipping address. Otherwise it will show the street physical address part.
The shipping address field is in the following format:
Street Address, City, State Zip
First attempt without inputting the City/State:
If(DataCardValue158.Selected.Value = "No", "TextName City/State",
//Input street address
Left(TextInput3_17Address,Find(",",TextInput3_17Address)-1))
This has no errors and works!
But I having trouble figuring out how to input the City/State of the shipping address for that new field.
I tried the following:
If(DataCardValue158.Selected.Value = "No",
"TextName "&
//Input City
First( Split( Last( Split(TextInput3_17Address, "," ) ).Result, "," ) ).Result
&"/"&
//Input State
Left(
Right(TextInput3_17Address,Find(",",TextInput3_17Address)-1), //Takes City Zip
Find(" ",Right(TextInput3_17Address,Find(",",TextInput3_17Address)-1)-1)), //Just takes City
//Input street address
Left(TextInput3_17Address,Find(",",TextInput3_17Address)-1))
I am not getting an error for the State when test out separately, but it doesn't do anything. It doesn't output the State.
And I get an error with the City part:
The function 'Split' has some invalid arguments.
Name isn't valid. 'Result' isn't recognized.
I need help with the City/State part.
Thanks for the help!