1 Reply Latest reply on Jun 12, 2011 8:51 PM by Lee Burrows

    Find and Replace

    jningatogo

      Hello all,

       

      I am trying to take a text input and search that for all instances of "a" and then in a label, add "001" where an "a" would be. And replace "A" with "002", ect.

       

      I appologize for my inexperience as I am very new to programming.

       

      Thanks

        • 1. Re: Find and Replace
          Lee Burrows Level 4

          hi

           

          there may be a more efficient way but try this (assuming your text input is myTextinput and your label is myLabel):

           

          var str:String = myTextinput.text;

          var search:Array = ["a", "A"];

          var replace:Array = ["001", "002"];

           

          var len:uint = search.length;

          for (var i:uint=0;i<len;i++)

          {

               while (str.indexOf(search[i])!=-1)

                    str = str.replace(search[i], replace[i]);

          }

          myLabel.text = str;

           

          just add more items to search and replace arrays (ensuring each array has same number of items)