1 Reply Latest reply on May 17, 2007 8:09 PM by

    How to Trim a dataField entry in MXML?

    theSaj
      Here is the situation. I am trying to read in an RSS feed. However, I am getting a large amount of white space in front of the entries. I want to "trim" the values.

      I've included mx.utils.StringUtil and this works text area and link button activities by using: StringUtil.trim(exampleGrid.selectedItem.title)

      However, this does not work for the actual datagrid entries which are populated merely by the name in quotes. So how do I apply the trim function to the datagrid entries.

      - Jason

      ------------------------------------------------------------------------------------------ ------------------------------------------------------

      <mx:Script>
      <![CDATA[
      import mx.utils.StringUtil;
      ]]>
      </mx:Script>

      <mx:HTTPService
      id="feedRequest"
      url="HTTP FEED"
      useProxy="false"/>

      <mx:Panel x="10" y="10" width="475" height="300" layout="absolute" title="{feedRequest.lastResult.rss.channel.title}">

      <mx:DataGrid x="20" y="20" id="exampleGrid" width="400" dataProvider="{feedRequest.lastResult.rss.channel.item}">
      <mx:columns>
      <mx:DataGridColumn headerText="Title" dataField="title"/>
      <mx:DataGridColumn headerText="Date" dataField="date"/>
      <mx:DataGridColumn headerText="Link" dataField="link"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:TextArea x="20" y="175" width="400" htmlText="{StringUtil.trim(exampleGrid.selectedItem.title)}"/>

      <mx:LinkButton x="20" y="225" label="Read Full Post" click="navigateToURL(new URLRequest(StringUtil.trim(exampleGrid.selectedItem.link)))"/>

      </mx:Panel>

      </mx:Application>
        • 1. How to Trim a dataField entry in MXML?
          <mx:Script>
          <![CDATA[
          private function trim(_value:String):String {
          var output:String = _value as String;
          while(output.substr(0,1).indexOf(' ') == 0)
          {
          output = output.substr(1,output.length-1);
          }
          while( output.substr(output.length-1,1).indexOf(' ') == 0 )
          {
          output = output.substr(0,output.length-1);
          }
          return output;
          }
          ]]>
          </mx:Script>


          <mx:TextArea x="20" y="175" width="400" htmlText="{ trim(exampleGrid.selectedItem.title) }"/>


          Probably not the most efficient way but it'll get the job done