0 Replies Latest reply on Nov 8, 2010 2:37 PM by MuskeeterAkshay

    Parsing Text File in Flex and saving it to database

    MuskeeterAkshay

      Hello,

         My Name is Akshay and I am trying to read and parse text files in flex.I am currently beginner in flex and currently having diffculty after reading the file. I also need to save it to the database after reading but if I am able to parse it appropriate it should be good.The code is as below

       

      <?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" minWidth="955" minHeight="600">

      <fx:Script>

      <![CDATA[

       

       

      public function  readFile(fName:String):void{

      var csvLoader: URLLoader = new URLLoader;

      csvLoader.load(new URLRequest(fName));

      csvLoader.addEventListener(Event.COMPLETE, loaderComplete);

      }

       

       

       

      function loaderComplete( event: Event) : void{

      var fileString: String = event.target.data;

       

      //fileString.replace("0","G1");

       

       

      var noNLStr: String =fileString.split(" ").join("\n");

       

       

      txtArea.text = noNLStr;

      }

      ]]>

       

      </fx:Script>

      <fx:Declarations>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

      <s:TextArea id="txtArea"

      creationComplete="readFile('location')"

      fontFamily="Tahoma" fontSize="11" fontWeight="bold" width="800" height="500"

      borderColor="#585858" borderAlpha="10"

      paddingLeft="10" color="#00000"  fontStyle="normal" />

      </s:Application>

       

      I am able to read the file without a problem into noNLStr variable without a problem. But I am sort of struggling on how to parse it further. The text file looks like below:

       

      false (indicator whether to read the file or not)

      0,355,841,0,0,0,6 ( multiple comma seperated values)

      5,560,837,0,0,0,12

      5,592,111,0,0,0,13

       

      The question is how should I proceed after getting noNLStr and then  get the comma seperated values from the text files individually..

       

      Comments and suggestion would be highly appreciated

       

      Thanks a lot in advance

      Akshay