Skip to content

TRIM Functional Keyword

Feature Since Version Notes
TRIM >v1.4.6 Removes leading/trailing whitespace

Overview

  • Description: Removes whitespace characters (spaces, tabs, newlines) from the beginning and/or end of a string.

Signature

  • Syntax:
    TRIM <sourceString>
    
    Note: Some implementations might offer options like TRIM_START or TRIM_END, but the basic TRIM typically handles both.

Parameters

  • <sourceString>: The string from which to remove leading/trailing whitespace. Can be a literal string, PAYLOAD, GET TOPIC result, or a {variable}.

Return Value

  • Description: Returns a new string with leading and trailing whitespace removed.

Usage Examples

Basic Example

Trim whitespace from user input before processing.

DEFINE ACTION ProcessUserInput
ON TOPIC "user/input" DO
    SET "cleanInput" = TRIM PAYLOAD
    IF {cleanInput} == "START" THEN
        PUBLISH TOPIC "command/result" WITH "Processing started..."
    ENDIF
* Scenario: Payload START arrives on user/input. {cleanInput} becomes START.

Intermediate Example

Clean up data retrieved from a topic before comparison.

DEFINE ACTION CheckCleanedDeviceID
ON TOPIC "check/device" DO
    SET "storedID" = GET TOPIC "config/device_id" // Might have extra spaces
    SET "trimmedID" = TRIM {storedID}
    IF PAYLOAD == {trimmedID} THEN
        PUBLISH TOPIC "check/result" WITH "Match Found"
    ENDIF

Notes & Additional Information

  • TRIM removes spaces, tabs, and newline characters from both the beginning and end of the string.