A simple version of the explode() function in PHP. It takes a string and splits it up into an array by splitting it at whatever character (or characters) you specify. For example, reading in a tab delimited text file. Will split it into lines by splitting on returns ("\r"). Then split up the lines by splitting on tabs ("\t").
Attribution: I didn't write this myself, I found it in a comment on one of the Actionscript on-line documentation pages.
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;
}