3 Replies Latest reply on Feb 12, 2008 10:32 AM by Gregory Lafrance

    Separating Text based on a character


      I have a datagrid that gets the data from an XML file which I can not change. For some reason, in one field there are two pieces of information separated by a "T", but I would like to use them separately. How can I do that?

      You can find the code below. What I want is to use the data stored in <SaleDate> in two diferent fields, based on the "T" character .


      Here is the flex code

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" creationComplete="catalog.send()">
      <mx:HTTPService url="data/catalog_BCA.xml" useProxy="false" id="catalog" />
      <mx:DataGrid dataProvider="{catalog.lastResult.Import.Auction}" width="100%" height="100%" x="0" bottom="0">
      <mx:DataGridColumn headerText="" itemRenderer="TipoLeilaoRenderer" width="70"/>
      <mx:DataGridColumn headerText="Tipo de Leilão" dataField="SaleTypeName"/>
      <mx:DataGridColumn headerText="Data" dataField="SaleDate"/>
      <mx:DataGridColumn headerText="Local" dataField="BranchName"/>

      <?xml version="1.0" encoding="UTF-8"?>
      <SaleDescription>GE-Direct LISBOA Jan 31 200</SaleDescription>
      <SaleDescription>Online LISBOA Jan 31 200</SaleDescription>
        • 1. Re: Separating Text based on a character
          Gregory Lafrance Level 6
          You could use regular expressions and parse the field with a regular expression like this (you could parse it in many different ways):


          See these help topics:
          Introduction to Regular Expressions
          Using Regular Expressions
          Regular expression syntax
          • 2. Re: Separating Text based on a character
            OffCourse Level 1
            Thank you for your answer. So this can only be done using Actionscript, right?

            I am kind of new to actionscript programming, as I am to Flex, but I am an adventurer, so I'll sort it out..

            Just so I do not ask you to place a sample code, can you please just point me in the right direction?

            In general, what I should do is an itemRenderer that takes the field data into actionscript and then turns it in two different variables separating it by the "T" character; or should I get the whole XML data, separate the field in two, turn all of it into a new array and THEN use that one as dataprovider for the datagrid?

            • 3. Re: Separating Text based on a character
              Gregory Lafrance Level 6
              It depends on how you want to use the data that is split from the date field. If the two parts will be manipulated and then go in one data grid column, then maybe you can do this in one itemrenderer, if the two parts will be placed in two columns, maybe you need two itemrenderers that basically do the same thing but take either the left part or the right part, though you should be able to create one renderer that can handle both cases.