Posted on 23rd November 2007 in ActionScript | 21 Comments »
Another snippet for free — String.replace() prototype for Flash that can be used to replace a pattern in a String.
The code of the String.replace() prototype is very simple and somewhat similar to the PHP’s str_replace function:
// initial string with a placeholder var str:String = '$person is welcome to flash tekkie'; // replace $person with 'Flash developer' and trace it var replacedStr:String = str.replace('$person','Flash developer'); trace(replacedStr);
As seen above method takes 2 arguments. Firstly a string pattern to search for and secondly a string to replace the pattern(s) found. Method returns a String.