I have just started with .NET programming and I had a question as to how I should go about doing this data manipulation.
Its a little hard to explain exactly what I want but bare with me.
What I have are documents that are formatted like so
This continues based on simulation that has been run. The data sets all start with Option.Code:Option $Comment Value 5.5 6.6 77 Value 3.0 .04 .90 DP -2 3 4 Value 02 9 84 XPAR 34 55 33 ... Option $Comment ...
What I want to do is scan through the document line by line (because I'm terrible with regular expressions) and search for "XPAR". If I find "XPAR" I need to delete that entire Option. That is I need to decriment and delete each line back up to Option and then skip foward to the next "Option" and continue to write to a new file.
So the new file will not have the data set "Option" where "XPAR" is found.
My idea was to read line by line into a temporary file until i found Xpar, then search back up and delete lines until i get to Option, skip to the next Option and continue to read line by line. This is the function that I have so far.
I don't know a whole lot about FileStreams, StreamReader/Writers so I don't really know how to go about scanning up and deleting while writing to the file.Code:Friend Sub import(ByVal strInputFile As String) Dim tmpFile As String = Path.GetTempFileName() Dim fsTemp As New FileStream(tmpFile, FileMode.Create) Dim sr As StreamReader = New StreamReader(strInputFile) Dim sw As StreamWriter = New StreamWriter(tmpFile) While sr.Peek() > -1 sw.WriteLine(sr.ReadLine) If sr.ReadLine.Contains("CCONE") Then End If End While sr.Close() sw.Close() fsTemp.Close() File.Delete(tmpFile) End Sub
Any suggestions or tips?




Reply With Quote