I was unable to find a String replace function in Flash 8 (then again I don’t know a whole lot about actionscript ) … so i came up with my own:
// these two are needed, and are from the Kirupa flash 'bestof_search'
//
/*
* contains()
* @param String
* @return int
*/
String.prototype.contains = function(searchString){[INDENT]return (this.indexOf(searchString) != -1);[/INDENT]
}
/**
* contains()
* @param String searchvalue
* @return bool
*/
Array.prototype.contains = function(searchValue){[INDENT]var i = this.length;[/INDENT]
[INDENT]while(i--) if (this* == searchValue) return true;[/INDENT]
[INDENT]return false;[/INDENT]
}
//
// these are my functions, feel free to use them
//
/**
* Replaces characters within a string
* replace(string|char, string|char)
* Method Speed: 1
* Method Type: recursive
* @param String|char instanceToReplace
* @param String|char replacement
* @return string
*/
String.prototype.replace = function(instanceToReplace, replacement) {[INDENT]if(!this.contains(instanceToReplace)) return this; // if the instance doesn't exist, ignore remaining code | this is our escape condition[/INDENT]
[INDENT]var prefix=substring(this,0,this.indexOf(instanceToReplace));[/INDENT]
[INDENT]var suffix=substring(this,this.indexOf(instanceToReplace)+instanceToReplace.length+1,this.length);[/INDENT]
[INDENT]this = prefix+replacement+suffix;[/INDENT]
[INDENT]return this.replace(instanceToReplace,replacement);[/INDENT]
}
// this function hasn't been thoroughly tested. fix it up if you need to
/**
* Replaces characters within a string
* replace(Array, string|char)
* Method Speed: n
* @param Array instances
* @param String|char replacement
* @return string
*/
String.prototype.replaceMultiple = function(instances, replacement) {[INDENT]for(i=0;i<instances.length;i++)[INDENT]this = this.replace(instaces*.toString(),replacement);[/INDENT]
return this;
[/INDENT]}