SerraAvenger
Cuz I can
- Reaction score
- 234
This is similiar to Romek's exploder, just that it works for seperators of a higher length than one, too.
It is only temporarily useful until Romek fixes that issue.
needs vJASS
Usage:
It is only temporarily useful until Romek fixes that issue.
needs vJASS
JASS:
library Splitter
globals
public string array Result
public integer Results = 0
endglobals
function StringSplit takes string toSplit, string splitter returns integer
local integer i = 0
local string tmp_Split = StringCase( toSplit, false )
local integer splitter_len = StringLength( splitter )
local integer lastI = 0
local integer nextI
local integer maxI = StringLength( toSplit ) - splitter_len
set splitter = StringCase( splitter, false )
set Results = 0
loop
exitwhen i > maxI
set nextI = i + splitter_len
if SubString( tmp_Split, i, nextI ) == splitter then
set Result[ Results ] = SubString( toSplit, lastI, i )
set Results = Results + 1
set lastI = nextI
else
set nextI = i + 1
endif
set i = nextI
endloop
if lastI != maxI then
set Result[ Results ] = SubString( toSplit, lastI, StringLength( toSplit ) )
set Results = Results + 1
endif
return Results
endfunction
endlibrary
Usage:
JASS:
local integer results = StringSplit( "abcfundeffun", "fun" ) // returns Splitter_Results.
local string array result
if results == Splitter_Results then
call BJDebugMsg( Splitter_Result[ 0 ] ) // Displays "abc"
//! runtextmacro PassSplitters( "result" ) // This textmacro passes all splitters into the specified string array.
call BJDebugMsg( Splitter_Result[ 0 ] ) // Displays "(null)"
endif