First timer here, I am attempting to create a number of complex Label expressions in Arc Map. The problems is, how do you get a specific piece of a sting that is in a long text field. For example i am trying to say: if a field contains the string "ATM" then create a label "ATM. See below snippet.
No a simple DQ or Schema change will not work as I need to create labels based on all these categories and then push them to a SDE database ENV. I am trying to improve my python ability. Please any help would be much appreciated. Thanks.
Solved! Go to Solution.
def FindLabel ( [NOTES] 😞
if "ATM" in [NOTES]:
return "ATM"
This worked great! Thanks everyone.
Maybe instead of the == in the operator, use "in".
This site has some info on using the "in" operator:
https://stackabuse.com/python-check-if-string-contains-substring/
split Notes by the commas to produce a list, trim the resultant strings if necessary and see if ATM is in the list
I don't have an IDE available, but
val_lst = [i.trim() for i in [Notes].split(",")]
if "ATM" in val_lst:
....
thank you, so are you trying to loop an array?
There is a Python str.find() method.
I will also give this a try. Have you ever tired using it in a Label expression? That is mostly where I am struggling. The expressions seems to behave different then a normal python IDE environment. Thank you so much for the help!
I understand what you mean about the different convention with field names having to be in brackets, but I re-tested using str.find() and it works as expected in a label expression.
Thank you so much can't wait to try it.
def FindLabel ( [NOTES] 😞
if "ATM" in [NOTES]:
return "ATM"
This worked great! Thanks everyone.