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?

890
4
05-19-2017 11:25 AM
BobBoutiette1
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)
0 Kudos
4 Replies
JoeBorgione
MVP Emeritus

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.

That should just about do it....
0 Kudos
DavidFox
New Contributor III

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 ...

0 Kudos
DanPatterson_Retired
MVP Emeritus
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'
0 Kudos
DavidFox
New Contributor III

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

0 Kudos