0

我正在使用 vb.net .am 有一个文件。该文件包含一些值。我想使用 vb.net 读取该文件。

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
4

1 回答 1

1

解析数据的关键是使用“SPLIT”方法

这是我敲出的示例代码。我不能确定它是 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
于 2012-12-17T01:44:29.170 回答