Actionscript Snippets: Explode() function

Snippet Name: Explode() function
Submitted By: Mark
Description: You can use to function the same way it is used in PHP

Snippet

function explode(separator:String, string:String) {
 
var list = new Array();
if (separator == null) return false;
if (string == null) return false;
var currentStringPosition = 0;
while (currentStringPosition<string.length) {
 
var nextIndex = string.indexOf(separator, currentStringPosition);
if (nextIndex == -1) break;
var word = string.slice(currentStringPosition, nextIndex);
list.push(word);
currentStringPosition = nextIndex+1;
 
}
if (list.length<1) {
 
list.push(string);
} else {
list.push(string.slice(currentStringPosition, string.length));
 
}
return list;
 
}