Best way in Xano to concatenate a full address from parts that needs to be stored in table

Options

I need to concatenate a full address from it's individual geocoded parts where some of the parts of the address may be null. The result needs to be stored in the table.

I know what I need to do, just not sure of the best way in Xano. This is part of an API call.

Parts include:

  1. StreetNumber
  2. StreetDirPrefix
  3. StreetName
  4. StreetDirSuffix
  5. City
  6. State
  7. Zip

I was trying to build a variable using Sprintf, however, I am having trouble eliminating the unneeded spaces when using something like Sprintf when one of the values is null.

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    The extra spaces I would fix after the fact by using a replace filter. Target two spaces (e.g. " ") and replacing with one space (e.g. " "). That "make a mess then clean it up" approach can be pretty effective.

  • dsturnerville
    Options

    Thanks Ray. That did the trick.

    For those that are new like me, here is the way I set this up. Ray, let me know if there is a more streamlined way.

    I still struggle with knowing when to use dot notation vs Get filters for values, however I just default to using a Get filter when the value could possibly be null, and dot notation everywhere else.

    These are the function stack steps.

    Here is the variable setup using Sprintf with some of the basic formatting in place.

    These are the Sprintf arguments. I am using a Get filter to get the value since it is coming from an API call and I don't know if the value will be null.

    Here I am cleaning up the variable by removing unneeded spaces created when null values were passed into the Sprintf filter. Since there were spaces between my arguments, when a null value gets passed, the space still exists and needs to be removed.