1 Reply Latest reply on Aug 11, 2007 5:03 PM by Handycam

    Replacing words in a string?

    Handycam Level 1
      I've got a string where I need to replace multiple instances of a word with a string.

      A simpler example would be "Four score and # years ago" -- where I need to insert a string variable instead of "#".

      I have been doing something like:

      var re : RegExp = /(#+)/ ;
      var _results:Array = _myString.split(re);

      And my plan was to use "results.splice()" to add the string. However, in the real string there are several "#" to replace, and it seems my way would get unwieldy.

      Is there a more efficient way?