Jump to content

split suggestion


Recommended Posts

Posted

function split should have parametr like "tryFormat" example

result=split("mystring,123,mystring",",",true) -- true is "try format"

result is table {"mystring",123,"mystring"} insted {"mystring","123","mystring"}

  • MTA Team
Posted
function splitf(input, separator)
    local output = split(input, separator)

    for index = 1, #output do
        local fragment = output[index]

        if fragment:match("^%d") then
            output[index] = tonumber(fragment:match("^%d+%.?%d+"))
        end
    end

    return output
end

Example:

output = {"Hello", "123", "World", "123prefix", "3.141wtf", "suffix456"}
1    Hello      string
2    123        number
3    World      string
4    123        number
5    3.141      number
6    suffix456  string

 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...