Skip to content

SPLIT Functional Keyword

Feature Since Version Notes
SPLIT >v1.5.8 String splitting using delimiters

Overview

  • Description: Splits a string into parts based on a delimiter. Useful for parsing CSV data, extracting fields from structured payloads, or breaking down topic paths.

Signature

  • Syntax:
    SPLIT <sourceString> USING <delimiter>
    

Parameters

  • <sourceString>: The string to split. Can be a literal string, PAYLOAD, GET TOPIC result, or a {variable}.
  • <delimiter>: The character or string used to split. Common delimiters include ,, ;, |, or custom strings.

Return Value

  • Description: Returns an array of strings, each representing a segment of the original string split by the delimiter.

Usage Examples

Basic Example

Split CSV data from a sensor:

DEFINE ACTION ParseCSVData
ON TOPIC "sensors/csv_data" DO
    SET "values" WITH SPLIT PAYLOAD USING ","
    PUBLISH TOPIC "sensors/parsed" WITH {values}

Scenario: Payload "25.5,60.2,101.3" is split into array ["25.5", "60.2", "101.3"]

Intermediate Example

Extract specific fields from split data:

DEFINE ACTION ExtractSensorFields
ON TOPIC "sensors/data" DO
    SET "fields" WITH SPLIT PAYLOAD USING ";"
    SET "temperature" WITH {fields}[0]
    SET "humidity" WITH {fields}[1]
    SET "pressure" WITH {fields}[2]

    PUBLISH TOPIC "sensors/temperature" WITH {temperature}
    PUBLISH TOPIC "sensors/humidity" WITH {humidity}
    PUBLISH TOPIC "sensors/pressure" WITH {pressure}

Advanced Example

Parse pipe-delimited log entries:

DEFINE ACTION ParseLogEntry
ON TOPIC "logs/raw" DO
    SET "parts" WITH SPLIT PAYLOAD USING "|"
    SET "timestamp" WITH {parts}[0]
    SET "level" WITH {parts}[1]
    SET "message" WITH {parts}[2]

    IF {level} EQUALS "ERROR" THEN
        PUBLISH TOPIC "logs/errors" WITH {message}
    ELSE
        PUBLISH TOPIC "logs/info" WITH {message}

Using SPLIT with CSV Format

SPLIT can be combined with the CSV data format indicator:

PUBLISH TOPIC "data/split" WITH SPLIT PAYLOAD USING CSV

This uses comma as the default delimiter for CSV parsing.

Notes & Additional Information

  • Array indexing is zero-based: {array}[0] is the first element
  • Delimiter is case-sensitive
  • Empty strings between consecutive delimiters are included in the result
  • Useful for parsing structured text data without JSON