Remove spaces
September 24th, 2009
Busy busy busy…. I’ve been too busy to blog for longer than I can remember.
I’ve got loads of stuff to post, but it needs a bit of cleaning up first (as most of it suffered late night last-minute hacks to accommodate client changes).
But anyway, here’s a simple little String function that removes any spaces from the start or end of a String, and removes any multiple spaces from within a String.
For example:
Input: " Hello world " Output: "Hello world"
Here’s the code (Flash AS3):
function removeSpaces(string:String):String{
//remove spaces at start
while(string.substr(0,1) == " "){
string = string.substring(1);
}
//remove multiple spaces in middle
while(string.indexOf(" ") != -1){
string = string.split(" ").join(" ");
}
while(string.substr(-1) == " "){
string = string.substr(0,string.length-1);
}
return string;
}
Might save you five minutes!
Sequence Randomiser
February 2nd, 2009
So I said I’d be back and here I am. I won’t bore you with specific excuses but I’ve honestly had a lot to do in the last few months.
Here’s another simple utility that came out of something old. It simply returns an array of consecutive integers, only in a random order, with no reptition. By default the smallest value is zero and the highest is the length of array requested – 1. However you can set the base value via an optional second argument.
A typical usage would be to trigger a number of animations in a random order.
Again, simple stuff but if it saves you 10 minutes then this post was worthwhile.
Files:
com.aderowbotham.utils.SequenceRandomiser
Usage:
import com.aderowbotham.utils.SequenceRandomiser; //create a sequence of length 10 var mySequence:Array = SequenceRandomiser.createSequence(10); trace(mySequence); //e.g. 5,0,7,8,2,4,1,9,6,3 //create a sequence of length 10, from -5 mySequence = SequenceRandomiser.createSequence(10,-5); trace(mySequence); //e.g. -4,-5,0,-3,2,1,3,-2,4,-1
Source
August 10th, 2008
To kick off (and I’ve not got anything else ready) I’ve posted some AS3 source code. At the moment, this just contains my utils directory and doesn’t really do much on its own. The rest will slot into this folder structure as and when it’s ready:
You may find a few handy bits and pieces in there. There’s not much at present but I reuse these classes a lot.