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:
Note: Some implementations might offer options like
TRIM_STARTorTRIM_END, but the basicTRIMtypically handles both.
Parameters
<sourceString>: The string from which to remove leading/trailing whitespace. Can be a literal string,PAYLOAD,GET TOPICresult, 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..."
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"
Notes & Additional Information
TRIMremoves spaces, tabs, and newline characters from both the beginning and end of the string.