Module:SplitString

Revision as of 19:38, 9 August 2019 by Joseph.Wharfe (talk | contribs)

local p = {}

function mw.ustring:split( inSplitPattern )
 
    local outResults = {}
    local theStart = 1
    local theSplitStart, theSplitEnd = mw.ustring.find( self, inSplitPattern, theStart )
 
    while theSplitStart do
        table.insert( outResults, mw.ustring.sub( self, theStart, theSplitStart-1 ) )
        theStart = theSplitEnd + 1
        theSplitStart, theSplitEnd = mw.ustring.find( self, inSplitPattern, theStart )
    end
 
    table.insert( outResults, mw.ustring.sub( self, theStart ) )
    return outResults
end

function main( frame )
    local myString = "Flintstone, Fred, 101 Rockledge, Bedrock, 98775, 555-555-1212"
 
    local myTable = p.myString.splitString:split( ", " )

    local outputString

    for i = 1,#myTable do
        outputString = outputString .. ( "[[" .. myTable[i] .. "]]" )
    end
    return outputString
end

return p