How do I write and expression that will not use the second word in a text string. I have a field titled (County) that has the word county after each name. (Sherman County, Logan County...). I am open to any language. Thanks
Solved! Go to Solution.
Using Arcade
Replace($feature.COUNTY, 'County', '')
Thank you, that worked great!
a = ['Sherman County', 'Logan County', 'Bob', 'One too many County']
b = [" ".join(i.split(" ")[:-1]) if " " in i else i for i in a]
b
['Sherman', 'Logan', 'Bob', 'One too many']
should cover most situations.
If you have <nulls>, use
b = [" ".join(i.split(" ")[:-1]) if hasattr(i, '__iter__') else i for i in a]
b
['Sherman', 'Logan', None, '', 'One too many']
because replace will fail
c = [i.replace("County", "") for i in a]
Traceback (most recent call last):
File "<ipython-input-18-40adfd4bc002>", line 1, in <module>
[i.replace("County", "") for i in a]
File "<ipython-input-18-40adfd4bc002>", line 1, in <listcomp>
[i.replace("County", "") for i in a]
AttributeError: 'NoneType' object has no attribute 'replace'