Hi there,
I have been struggling with this for quite a while now. I am a novice in .net so no wonder I can figure it out.
I have a tab delimited file, where the sequence of lines should be
01UN1........................
04UN1..........................
09UN1........................
01UN2....................
04UN2.............
04UN2...............
09UN2................
However sometimes in the file we have redundant 04 rows, which need to be removed , so that the last one is the true one that should tremain in the file, the one in red should be deleted.
I started creating a console application and from what I read online and in books I figured I will need the file in an array.So I managed to input the file into a string array and then write it to a new text file.
Here is my code:
Imports System
Imports System.Console
Imports System.IO
Module Module1
Sub Main()
' text document to array
Dim myarray As String()
myarray = File.ReadAllLines("C:\Original.txt")
Dim i As Integer = 0
i = i + 1
For i = 0 To myarray.GetUpperBound(0)
Next
'write the array to a new text file
System.IO.File.WriteAllLines("C:\newfile.txt", myarray)
End Sub
End Module
I now need to loop through every row and take the part 01UN1 from the line and see if the next line starts with 04UN1, if so check if the line after starts with 09UN1. if that's correct then write the three lines in the new file, then go to next line that starts with 01it could be 01UN2 for example and do the same check. If there are more hatn one 04UN2 lines then delete all and leave only the last one then continue onwards until the end of the file.
the unique part of every row would be the string between 3 and 6character of the line. So if we have as unique part UN1 then we need only have rows :
01UN1
04UN1
09Un1
and then continue from the following line that starts with 01 and has different unique identifier for example UN5 to say.
I am not sure how do I reference each row from the array, also I need to set that unique identifier as a variable and then use if conditions . Not even sure i that's the right track.
Also I cannot be sure what the list of unique parts for every file would be so I can put them in a separate file and compare against them, so checks should be made against unique parts present in the files at rows starting with 01. Also we would only have redundant rows starting with 04.
If someone can help me out here I would be really grateful.
Thanks in advance