Module:SplitString: Difference between revisions

From YSTV History Wiki
Jump to navigation Jump to search
(Created page with "function string:split( inSplitPattern ) local outResults = {} local theStart = 1 local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )...")
 
No edit summary
Line 1: Line 1:
function string:split( inSplitPattern )
function mw.ustring:split( inSplitPattern )
   
   
     local outResults = {}
     local outResults = {}
     local theStart = 1
     local theStart = 1
     local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
     local theSplitStart, theSplitEnd = mw.ustring.find( self, inSplitPattern, theStart )
   
   
     while theSplitStart do
     while theSplitStart do
         table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
         table.insert( outResults, mw.ustring.sub( self, theStart, theSplitStart-1 ) )
         theStart = theSplitEnd + 1
         theStart = theSplitEnd + 1
         theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
         theSplitStart, theSplitEnd = mw.ustring.find( self, inSplitPattern, theStart )
     end
     end
   
   
     table.insert( outResults, string.sub( self, theStart ) )
     table.insert( outResults, mw.ustring.sub( self, theStart ) )
     return outResults
     return outResults
end
end

Revision as of 18:18, 9 August 2019


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