I am trying to put 3 fields together with no spaces and some of them are null. I tried the following expression: !AssetID!.replace("zero", str(!CSubdivision! + !CBlock! + !CLot! ))
If any of the fields are null, then the AssetID field also ends up null. I am trying to find a way around this and this is what I've come up with so far. I get keep getting a parcing error and I don't understand why. Can I return an expression? If not, how would I go about getting rid of the null values without changing my data?
(I'm using 10.4)
Solved! Go to Solution.
If by "put 3 fields together" you mean concatenate three fields with mixed data types, and possibly having NULL values, then try the following in the expression dialog box:
"".join(str(i).strip() for i in (!CSubdivision!, !CBlock!, !CLot!) if i)
you can jump through hoops trying to get every incarnation to work, or
1 fix the inputs so that you use a 'null value' that is recognized such as "nodata" as a string for text fields or -99999 or some ridiculous number that isn't possible for your numeric fields.
Then concatenation is easy.
In your case, I would query for the condition were all three fields, individually Is NOT Null, then do the field concatenation in the field calculator.
if any of the fields are numeric, they need to be converted to string first ie.
str(!fieldA!) + str(!fieldB!)+str(!fieldC! or learn the new formatting language... it does the conversion and concatenation for you
"{}{}{}".format("be",1,"with the universe")
If by "put 3 fields together" you mean concatenate three fields with mixed data types, and possibly having NULL values, then try the following in the expression dialog box:
"".join(str(i).strip() for i in (!CSubdivision!, !CBlock!, !CLot!) if i)