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

593
3
Jump to solution
11-25-2019 04:45 PM
TomTinney
New Contributor

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

0 Kudos
1 Solution

Accepted Solutions
MarkBockenhauer
Esri Regular Contributor

Using Arcade  

   Replace($feature.COUNTY, 'County', '')

View solution in original post

3 Replies
MarkBockenhauer
Esri Regular Contributor

Using Arcade  

   Replace($feature.COUNTY, 'County', '')

TomTinney
New Contributor

Thank you, that worked great!

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
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'