quicksplit

here is an enhanced version of brandon hall's split which is faster than the original split, is able to split by an empty string into an array of chars and is able to split by words. Insert this script in the first frame of your movie to add the new and faster quicksplit command to the string objects. String.prototype.quicksplit = function (d){ var result = new Array(); if(d == null){ result[0] = this; } else { var i = 0; var pos = 1; var size = this.length; var dsize = d.length; if (dsize >= 1){ while(++i<=size){ if (substring(this, i, dsize) == d){ result.push(substring(this, pos,(i-pos))); pos = i+dsize; } } if(pos < i) result.push(substring(this, pos)); } else { while(i<=size){ result.push(substring(this,i++,1)) } } } return result; } //usage s = "Lazy brown fox"; trace(s.quicksplit("")); trace(s.quicksplit("brown")); trace(s.quicksplit(" "));
Stanislav Vasilev Date: 12/10/2001

It would be first if you run throught the characters with chatAt. At least I tried out your method ad it\'s fast, my is faster. BTW, also wanna say this site is great I\'ve learned much. The convex poly drawing algo is great idea.
Tim Date: 20/02/2002
Hi Ralf, There is one improvement you could make to gain some speed. Since your function can split with a string rather than only a single character, you could replace: pos = i+dsize; // by pos = (i += dsize - 1) + 1; so that after a delimiter is found, you don't have to go through the characters that make up the delimiter in the original string. For large string delimiter, you can gain consequent speed this way. Also for a very minor speed increase, you don't have to check all untill the last character of the original string if your delimiter is more than one character long. I changed the function a bit like this: var size = this.length var lastPos = size - dsize + 1; //and then: while(++i <= lastPos) { Cheers, Tim.
Add comment
Home