Jump to content
Gold Sponsor: Data-Way IT-Consulting, Austria

  • StringSplitToTable()

    StringSplitToTable()

    Lua   SwxWare v13.10

     

    This helper function splits parts of a given string, separated by a given separator, into a table.

     

    local tParts = StringSplitToTable(sInput, sSeperator)

     

     

    This function returns a table of string values.

     

     

    Example:

     

    local tParts = StringSplitToTable("111;222;333;444", ";")
    
    for i = 1, #tParts do
        PBXScript.OutputTrace("tParts[" .. tostring(i) .. "] = " .. tParts[i])
    end
    
    --> tParts[1] = 111
    --> tParts[2] = 222
    --> tParts[3] = 333
    --> tParts[4] = 444

     

     

    Please note: if you are still using a "Lua Beta Testing" version of SwyxWare (i.e. v13.1x), you need to copy&paste the following function into the Start block of your GSE script as it wasn't a build-in helper function yet.

     

    -- split parts of string, separated by a given separator, into a table
    function StringSplitToTable ( sInput, sSeperator )
        local t={}
        if (sSeperator == nil) then
            sSeperator = "%s"
        end
        if (type(sInput) == "string") then
            if (type(sSeperator) == "string") then
                for sStr in string.gmatch(sInput, "([^".. sSeperator .."]+)") do
                    table.insert(t, sStr)
                end
            end
        end
        return t
    end

     

     


    Tom Wellige
     Share


     Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.