Dynamic Whitespace Trimming in Logic Blocks

Currently it looks like the trim function only supports removing exact matching characters or strings from the start and/or end of a value. This limitation makes it difficult to handle scenarios where incoming data contains unpredictable whitespace padding (e.g. fixed-width fields from systems like JDE).
External system fields often include variable leading or trailing spaces that are not consistent in length or pattern. At present, trimming requires knowing the exact character sequence to remove.

Is there any recommended approach within Logic Blocks to overcome this limitation (for example handling unknown or variable whitespace padding), or any best practice workaround currently used in similar integration scenarios?

Hi Jaco!

I’ve got a few ideas to share.

1 - Single character trimming

Trimming shouldn’t require an exact character sequence if all of the characters are the same, which is typically true in padding scenarios. You can provide a single exact character, for example a space , and ALL characters that match that one character will be trimmed from the beginning and end of the text. So blah will become blah just by using Trim with one .

2 - Replace + Trim (easiest way to handle many types of whitespace, doesn’t work if you need real whitespace in your text)

If you have multiple types of whitespace (e.g. tab, new lines), does the Replace function of Text Manipulation satisfy your need? You can replace all whitespace characters with nothing, effectively removing them. You may need to chain multiple actions, for example replacing space, tab, and any other whitespace characters you need to support.

If your input strings may contain legitimate spaces, then this won’t work.

3 - Trim in a loop (most comprehensive | more code)

You can also Trim repeatedly if you may have a mix of multiple whitespace characters, trimming one whitespace character at a time. You can iterate using the Loop Conditional action, exiting when your trimmed text looks the same as the text you started with (in other words, exit the loop when the trim stops doing anything).


We do not have anything in the system today that detects “whitespace” automatically. You can work with your customer support representative to request that as a feature.

Hi Brendan, I tried the single exact character trimming and it is only trimming one character. In my exampe I have "Warehouse MOR " which has 17 spaces. When I specify Trim from End and I use a constant value of a space, the data in the debugger is returned where "Warehouse MOR " now has 16 spaces so only 1 space was trimmed. If I specify 17 spaces as a constant value then only does it trim 17 spaces correctly.

Interesting. Sorry for the misinformation. I’m talking with some folks to see if this is a bug and if we might be able to change that behavior to match what I expected, but it does look like it’s always worked the way you’re experiencing.

In the meantime, you can combine that single-character-trimming with a loop like so:

This will repeatedly trim the character 1 from FieldToTrim until there is nothing left to trim. Replace that with for your use case (I used 1 because it’s easier to read as an example) and you should be good to go.

We’re all in agreement that this behavior is confusing and looks like a bug. It would be more intuitive and useful for Trim to remove all 17 spaces from “Warehouse MOR” when a single constant space is provided as input.

If you are a Nextworld customer or partner, work with your system administrator to submit a ticket with customer support, who will file a bug on your behalf. Include a link to this post in the ticket. If you’re not a Nextworld customer, keep an eye on release notes. We’re always making improvements.

Thank you Brandan, I am going to implement this as suggested. We have logged a bug https://sdsupport.nextworld.net/support/tickets/436949