Hello,
does anyone know of an expression that can help me make a label of everything before the first space within a field??
Example:
Home numbers of an address field.
Solved! Go to Solution.
Using Python Parser.
def FindLabel ( [fieldname]):
return [fieldname].split(" ")[0]
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 [0])
Using Python Parser.
def FindLabel ( [fieldname]):
return [fieldname].split(" ")[0]
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 [0])
Thank You Ian for introducing Split concept, I was able to use this in the field calculator with python parser
!fieldname!.split(" ")[0]
Emmanuel,
Please mark Ian's response as Correct to close out this thread.
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[0]
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.