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

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »