1 Reply Latest reply on Feb 3, 2010 4:11 PM by Peter deHaan

    Array - sepatare elements with spaces

    el_kolo

      Hi,

       

      Is it possible to replace commas in Array output with spaces?

        • 1. Re: Array - sepatare elements with spaces
          Peter deHaan Level 4

          Instead of array.toString(), use array.join(" "):

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                         xmlns:s="library://ns.adobe.com/flex/spark" 
                         xmlns:mx="library://ns.adobe.com/flex/mx"
                         creationComplete="init();">
              <s:layout>
                  <s:VerticalLayout paddingLeft="20" paddingTop="20" />
              </s:layout>
              
              <fx:Script>
                  <![CDATA[
                      private function init():void {
                          var arr:Array = ['One', 'Two', 'Three', 'Four', 'Five'];
                          lbl1.text = "toString(): " + arr.toString();
                          lbl2.text = "join(' '): " + arr.join(' ');
                      }
                  ]]>
              </fx:Script>
              
              <s:Label id="lbl1" />
              <s:Label id="lbl2" />
              
          </s:Application>
           
          

           

          Peter