Module:SplitString

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

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 = myString.splitString:split( ", " )

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