Flash string search replace using prototype

How to preform a string search and replace in flash using actionscript prototype
A prototype to replace a pattern in a string

String.prototype.replace = function(pattern, replacement) {
return this.split(pattern).join(replacement);
}

To use the prototype

var str = "hello world";
var newstr = str.replace("world", "Earth");
trace(newstr);

This will output: Hello Earth

Tagged : / / / /

Leave a Reply

Your email address will not be published. Required fields are marked *