3 Replies Latest reply on Nov 16, 2010 4:32 AM by Ned Murphy

    Splitting up strings

    celebritymusic Level 1

      Hi

       

      I'm trying to take the letters I have in a string var, eg "EXAMPLE", and display them in a textField like so:

       

      E

      X
      A
      M
      P

      L
      E

       

       

      Maybe I'm trying to make it too complicated, but I can't seem to figure it out.  I'm using the following code:

       

       

      var str:String = segmentName;


            var re:RegExp = /(\S)/;
            var results_array:Array = str.split(re);
           
            for (var i2:String in results_array)
      {
          text_field_mc.text = results_array[i2];
          trace(results_array[i2]);
      }

       

       

      The textFeild shows nothing (the textField is coded correctly, as it shows regular strings).  However, the trace shows it as:

       

      E

       

      X


      A


      M


      P

       

      L


      E

       

       

      I've got the textfield set large enough to accomodate the text.

       

      Is there a better way to split a string into individual letters, and then display them in a field one above the other?  I thought \n\r might have come into it, but I can't make them fit into the above example.

       

      Cheers

       

      Shaun

       

      Shaun