您可以嘗試類似如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application creationComplete="init(event)" xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
protected function init(event:FlexEvent):void
{
var beginningQuotesExp:RegExp = /^\s*"/gm;
var result:String = csvData.replace(beginningQuotesExp, "");
var endingQuotesExp:RegExp = /"\s*$/gm;
result = result.replace(endingQuotesExp, "");
var bodyQuotesExp:RegExp = /"\s*;\s*"/gm;
result = result.replace(bodyQuotesExp, ";");
var splitRegExp:RegExp = /\r*\n+|\n*\r+/gm;
var lines:Array = result.split(splitRegExp);
var dataProvider:ArrayCollection = new ArrayCollection();
for each (var line:String in lines)
{
var lineArray:Array = line.split(";");
var dataObject:Object =
{ counter: lineArray[0], email: lineArray[1], name: lineArray[2], phone: lineArray[3] };
dataProvider.addItem(dataObject);
}
dg.dataProvider = dataProvider;
}
]]>
</fx:Script>
<fx:Declarations>
<fx:String id="csvData">
<![CDATA["1";"[email protected]";"asdasdasd";"1302531993"
"2";"[email protected]";"werwetewt" ; "234235"
"3";"[email protected]";"werwetewt";"234235"]]>
</fx:String>
</fx:Declarations>
<mx:DataGrid horizontalCenter="0" id="dg" verticalCenter="0">
<mx:columns>
<mx:DataGridColumn dataField="counter" headerText="counter" />
<mx:DataGridColumn dataField="email" headerText="email" />
<mx:DataGridColumn dataField="name" headerText="name" />
<mx:DataGridColumn dataField="phone" headerText="phone" />
</mx:columns>
</mx:DataGrid>
</s:Application>
謝謝你的提示,它的工作漂亮! – Proyb2 2011-05-03 17:33:00