[pshaiCmd] StringJoinList

stable
By pshai in Miscellaneous Published April 2021 👁 1,099 views 💬 0 comments

Description

Custom command to concatenate list values into a single string.
HaasScript
-- Author: [email protected]

DefineCommand('StringJoinList', '')

local list = DefineParameter(ListDynamicType, 'list', 'List of values to be converted into a single string', true, {1, 2, 3, 4, 5}, '')
local separator = DefineParameter(StringType, 'separator', 'Separator text inserted between list values', false, ', ', '')

local ret = ''

if list and #list > 0 then
    local item, v

    for i=1, #list do
        v = Parse(ArrayGet(list, i), StringType)

        if i == #list then
            item = v
        else
            item = v .. separator
        end

        ret = ret .. item
    end
end

DefineOutput(StringType, ret, 'Output string', '')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!