does anyone know of an expression that can help me make a label of everything before the first space within a field??
Home numbers of an address field.
Using Python Parser.
def FindLabel ( [fieldname]): return [fieldname].split(" ")
I'm assuming that the field in question is a text field. This splits a text string by a space character(.split(" ") and returns the first portion of that string(actually splits the whole string into a list of strings and returns the first item of that list hence the )
Thank You Ian for introducing Split concept, I was able to use this in the field calculator with python parser
Please mark Ian's response as Correct to close out this thread.
This is not working for us in ArcGIS Pro. We are also trying to return everything before the first space (or drop everything after the first space). I attached a picture of what the Invalid Expression response was. Thank you in advance for saving the day
kathy walker: You may need to put exclamations around the [ADDRESS] in line 1:
Thank you Joe. We finally got something that works:
def FindLabel ( [Location] ): if [Location] == None: return "No Address" else: x = [Location] x1 = x.split(" ") return x1
kathy walker - I just gave the original expression a go and it worked for me. It appears that when using the python parsing tool ArcGIS Pro understands that exclamations are implied. (Like the use of quotes as well...) I thought your problem might have been None values, but my data has them too. Not sure what's up there....
One problem we discovered, the field we were using was indexed, it had an asterisk (Address*) in the header. As soon as we switched to a field that was not indexed we started getting somewhere.
Retrieving data ...