Attribute Assistant: I have a concatenated field that maintains blank spaces if a contributing field is null. How would I eliminate the spaces left from missing pre-direction and post-direction values?

372
4
05-19-2017 11:25 AM
Highlighted
New Contributor II

I have a the following value method in my dynamic value table#:

([ADDRNUM]+" "+[ROADPREDIR]+" "+[FULLNAME]+" "+[ROADPOSTDIR]+" "+[UNITTYPE]+" "+[UNITID])

When any of these values is null, the resulting concatenation contains extra spaces.  What would be the best way to ensure no extra spaces are created?

Thanks

Tags (1)
Reply
0 Kudos
4 Replies
Highlighted
MVP Esteemed Contributor

It seems odd to me that a blank space is inserted for a <null> value.  One thing that I do notice you are using the + operator.  You might try the & operator instead.  You could do a series of nested IIF statements to check of <null> values, but that's going to get ugly.

Reply
0 Kudos
Highlighted
New Contributor II

Bob, I have the same problem using the field calculator in a geodatabase feature class to concatenate values. I have tried a few snippets of things posted here and I either get a blank space where a <null> would be or the entire result is <null> when the calculation hits a <null> field. I've tried +  and & with similar results. I thought I had this licked once but can't find a saved .cal file so here I am again ...

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor
a = ['a', 'b', None, 'c', 'd']  # values from a field for demonstration

" ".join(["{}".format(i) for i in a if i])  # the trick is the 'if i' part

# ---- yields ---

'a b c d'
Reply
0 Kudos
Highlighted
New Contributor II

Rather than deal with nulls, I did a selection [Problem Field] IS NULL then used the field calculator to replace <null> with ""

Not very elegant, a bit tedious, but it works and then allows my old concatenation calculation to work properly. I've wasted enough time on solving this.

Dan, in another post you talk about not having tables with nulls. How do you create a new feature class in a geodatabase that contains no nulls?

Dave

Reply
0 Kudos