Module:SplitString: Difference between revisions

From YSTV History Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 20: Line 20:
     local myString = "Flintstone, Fred, 101 Rockledge, Bedrock, 98775, 555-555-1212"
     local myString = "Flintstone, Fred, 101 Rockledge, Bedrock, 98775, 555-555-1212"
   
   
     local myTable = p.myString.splitString:split( ", " )
     local myTable = myString.splitString:split( ", " )


     local outputString
     local outputString

Revision as of 19:41, 9 August 2019


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 p.main( frame )
    local myString = "Flintstone, Fred, 101 Rockledge, Bedrock, 98775, 555-555-1212"
 
    local myTable = myString.splitString:split( ", " )

    local outputString

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

return p