Arcade - Identify if text is present in field string

264
2
Jump to solution
07-08-2021 02:00 PM
Labels (2)
RoscoPeters17
New Contributor II
  • I have a field named: $feature["POSTAL_CODE"]. It contains zip codes.
  • I also have a list of zip codes: 28712, 28717, 28734 , 28736 , 28741...
  • My goal is to check each row of $feature["POSTAL_CODE"] against my list and if a code on my list is present return a 1 otherwise a blank
  • I put together the code below which works as intended, the only issue is that some of the zip codes in $feature["POSTAL_CODE"] are in zip+4 format (ex: 28712-xxxx). For these row my code does not work. I'm only concerned that the first 5 characters of the of the zip code string match. Is there a way to modify or rewrite this so that it works for the handful of rows that have the zip+4 format?

 

var zip = $feature["POSTAL_CODE"]

var aoi = ['28712','28717','28734','28736','28741']

IIF( indexof(aoi, zip ) > 0 ,'1',"")

RoscoPeters17_0-1625777561351.png

I'm relatively new to arcade so forgive me I refer to anything incorrectly. Also if any additional information is  needed please let me know. This is where I stand:

Thanks

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Notable Contributor

Try subsetting the postal code field:

var zip = Left($feature["POSTAL_CODE"], 5)

That way if there's anything more than 5 digits, you still just get the first 5.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Notable Contributor

Try subsetting the postal code field:

var zip = Left($feature["POSTAL_CODE"], 5)

That way if there's anything more than 5 digits, you still just get the first 5.

- Josh Carlson
Kendall County GIS
RoscoPeters17
New Contributor II

Thanks @jcarlson. Not sure why I didn't think of that.

0 Kudos