18 lines
577 B
Plaintext
18 lines
577 B
Plaintext
fcn multisplit(text, sep){
|
|
lastmatch := i := 0; matches := List();
|
|
while(i < text.len()){
|
|
foreach j,s in ([0..].zip(sep)){
|
|
if(i == text.find(s,i)){
|
|
if(i > lastmatch) matches.append(text[lastmatch,i-lastmatch]);
|
|
matches.append(T(j,i)); # Replace the string containing the matched separator with a tuple of which separator and where in the string the match occured
|
|
lastmatch = i + s.len();
|
|
i += s.len()-1;
|
|
break;
|
|
}
|
|
}
|
|
i += 1;
|
|
}
|
|
if(i > lastmatch) matches.append(text[lastmatch,i-lastmatch]);
|
|
return(matches);
|
|
}
|