I use the following coding which edits my text file based on the value in column being smaller than the value in a textbox.
Dim intValue As Integer
Dim intMaxValue As Integer = Integer.Parse(textbox1.Text)
Dim strSourceFile As String = IO.Path.Combine("G:\test.txt")
Dim OutPutFile As String = IO.Path.Combine("G:\test2.txt")
Dim strLines() As String = IO.File.ReadAllLines(strSourceFile)
Dim strFiltered As New System.Text.StringBuilder
Dim strTemp() As String
For Each strLine In strLines
If strLine.Trim.Length <> 0 Then
strTemp = strLine.Split(" "c)
If Trim(strTemp(0)) = "USER" AndAlso Trim(strTemp(2)) = "1" Then
strLine = strTemp(8).Trim & " " & strTemp(16).Trim
If Integer.TryParse(strLine.Split(" "c)(1), intValue) Then
If intValue <= intMaxValue Then
strFiltered.Append(strLine & Environment.NewLine)
End If
End If
End If
End If
Next
IO.File.WriteAllText(OutPutFile, strFiltered.ToString)
Now the above coding works perfectly, the output looks like the following:-
String1 100
String1 256
String1 500
String2 100
String2 256
String3 876
String3 345
String3 643
String3 102
String4 100
String4 084
String5 492
String5 178
String6 873
String6 156
String6 786
What I was hoping for was to add additional coding so i only want the String with the highest number showing so the above would look like
String1 500
String2 256
String3 876
String4 100
String5 492
String6 873
Would it be possible to add the final bit of coding?
UPDATE
Rather than checking the highest number and deleting the other fields, I wish to check each matching field in column 1 and check the highest number and if its greater than the field in textbox1 then remove all rows for that matching fields in column 1. If the highest number is lower than the field in textbox1, then keep that row but remove the other column 1 matching fields. So for example
String1 100
String1 256
String1 500
String2 100
String2 256
String3 876
String3 345
String3 643
String3 102
String4 100
String4 084
String5 492
String5 178
String6 873
String6 156
String6 786
So if textbox1 was to have 550 then you should have
String1 500
String2 256
String4 100
String5 492
Update 2
The value in textbox1 is
1341273599
When I only filter the columns to show column 1 and column 2 I get the following.
S00048 1428142557
S00048 1428141809
S00048 1338805621
S00048 1310295931
S00048 1309086124
S00048 1432203954
S00048 1431686625
S00048 1428142556
S00048 1431686626
S00048 1334743408
S00042 1324204635
S00040 1313659927
S00037 1308388943
S00033 1303118141
S00032 1391422317
S00032 1391422304
S00032 1298024019
S00032 1391422303
S00032 1391422316
So when I run the actual coding I get the following
S00048 1338805621
S00042 1324204635
S00040 1313659927
S00037 1308388943
S00033 1303118141
S00032 1298024019
You might be able to see that the end result is incorrect?
You could use a Dictionary to hold the values: