Hi
the code below will remove duplicate lines and sorting .
i would like to modify the code below to add more function
as
1- if g1,g2,g3,g4 =0 then line will be removed like
DDS,20110523,0,0,0,0,24
2-if g1,g2,g3,g4 =g4 of the line before then line will be removed like
the line as
DDS,20110526,1.1,1.1,1.1,1.1,29
DDS,20110525,2.4,2.7,2.3,1.1,22
the txt file contain more then 3000 lines and different q(clo 0)(name as DDS ,RRB,EES...etc) and date (clo 1)
the code i am using
thank you for your help
the code below will remove duplicate lines and sorting .
i would like to modify the code below to add more function
as
1- if g1,g2,g3,g4 =0 then line will be removed like
DDS,20110523,0,0,0,0,24
2-if g1,g2,g3,g4 =g4 of the line before then line will be removed like
the line as
DDS,20110526,1.1,1.1,1.1,1.1,29
DDS,20110525,2.4,2.7,2.3,1.1,22
the txt file contain more then 3000 lines and different q(clo 0)(name as DDS ,RRB,EES...etc) and date (clo 1)
the code i am using
Code:
Public Class AAABB
Friend Class DataItemList
Property DataItems As List(Of DataItem)
Friend Class DataItem
Public q As String
Public theDate As DateTime
Public g1 As Double
Public g2 As Double
Public g3 As Double
Public g4 As Double
Public g5 As Integer
Overrides Function ToString() As String
Return String.Format("{0},{1},{2},{3},{4},{5},{6}", q, theDate.ToString("yyyyMMdd"), g1, g2, g3, g4, g5)
End Function
End Class
Sub AddOrUpdate(d As DataItem)
If DataItems.Exists(Function(x) x.q = d.q AndAlso x.theDate = d.theDate) Then
Dim idx = DataItems.FindIndex(Function(x) x.q = d.q AndAlso x.theDate = d.theDate)
DataItems(idx) = d
Else
DataItems.Add(d)
End If
End Sub
Sub LoadData(src As String)
Using tfp = New TextFieldParser(src)
tfp.TextFieldType = FieldType.Delimited
tfp.Delimiters = {","}
tfp.ReadLine() ' skip headers.
Dim s As String()
Dim lineNo As Integer = 1 ' we've skipped the first line
While Not tfp.EndOfData
s = tfp.ReadFields
If s.Count = 7 Then
' you /should/ parse the data more thoroughly than this, e.g. with TryParse.
Me.AddOrUpdate(New DataItemList.DataItem With
{.q = s(0),
.theDate = DateTime.ParseExact(s(1), "yyyyMMdd", Nothing),
.g1 = Double.Parse(s(2)),
.g2 = Double.Parse(s(3)),
.g3 = Double.Parse(s(4)),
.g4 = Double.Parse(s(5)),
.g5 = Int32.Parse(s(6))})
Else
MsgBox(String.Format("Error in file {0} at line {1}.", src, lineNo))
End If
lineNo += 1
End While
End Using
End Sub
Sub New()
DataItems = New List(Of DataItem)
End Sub
End Class
Public Sub TEXTAAA()
Dim myData = New DataItemList
myData.LoadData("C:\AAAA.txt")
myData.LoadData("C:\BBBB.txt")
Dim sortedData = myData.DataItems.OrderBy(Function(d) d.q).ThenByDescending(Function(d) d.theDate)
' show the result
Dim objWriter As New System.IO.StreamWriter("C:\test.txt")
objWriter.Write(String.Join(vbCrLf, sortedData))
objWriter.Close()
System.Diagnostics.
Process.Start("notepad", "C:\test.txt")
End Sub
End Class
thank you for your help