2012-11-26 28 views
0

上午使用vb.net .am有一個文件。該文件包含一些值。我想用vb.net讀取那個文件。在vb.net中讀取文本文件爲csv

file name cdr_StandAloneCluster_03_201208090909_33121.file 

data type  file 

it contain the data look like this 


cdrRecordType,"globalCallID_callManagerId","globalCallID_callId","origLegCallIdentifier","dateTimeOrigination","origNodeId","origSpan","origIpAddr","callingPartyNumber","callingPartyUnicodeLoginUserID","origCause_location","origCause_value","origPrecedenceLevel","origMediaTransportAddress_IP","origMediaTransportAddress_Port","origMediaCap_payloadCapability","origMediaCap_maxFramesPerPacket","origMediaCap_g723BitRate","origVideoCap_Codec","origVideoCap 
+1

[你有什麼試過?](http://whathaveyoutried.com) – prprcupofcoffee

回答

1

的關鍵,解析您的DTA是使用「分離」的方法

這裏是一個示例代碼,我敲了起來。 我不能確定它的110%,但它應該讓你更接近解決你的問題。

Sub SomePrcoedure(strFilename As String) 

Dim arrRawData As Generic.List(Of String) = Nothing 
Dim arrLineItems() As String = Nothing 
Dim objStreamReader As StreamReader = Nothing 
Dim datTextLine As String = Nothing 

    '-> Validate Filename 
    If Trim(strFilename) <> "" Then 
     If FileIO.FileSystem.FileExists(strFilename) Then 
      '-> Read the WHOLE file in 
      arrRawData = New Generic.List(Of String) 
      objStreamReader = New StreamReader(Trim(strFilename)) 
      Do 
       datTextLine = objStreamReader.ReadLine() 
       If Trim(datTextLine) <> "" Then 
        arrRawData.Add(Trim(datTextLine)) 
       End If 
      Loop Until objStreamReader.EndOfStream() 
      objStreamReader.Close() 
      '-> Split EACH line data into the array arrLineItems 
      For intCounta = 0 To arrRawData.Count - 1 
       arrLineItems = Split(arrRawData(intCounta), ",") 
       'your line is now split into the array arrLineItems() 
       'process results here or store results for later or your code here.... 
      Next 
     Else 
      'file not found 
     End If 
    Else 
     'file name missing 
    End If 
    arrRawData = Nothing 
    arrLineItems = Nothing 
    objStreamReader = Nothing 
    datTextLine = Nothing 

End Sub