I need to format text file as delimeted and delete some fields. this is my code (vb.net, vs2008)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filename As String = "C:\temp\WaterPurge1.txt"
Dim Lines As New List(Of String)(IO.File.ReadAllLines(filename))
For Each Line In Lines
Dim count As Integer = Line.Count
Line = Line.Insert(49, "|")
Line = Line.Insert(110, "|")
Line = Line.Remove(110, count - 135)
Line = Line.Insert(137, "|")
Line = Line.Remove(50, 53)
'Line = Line.Remove(141, 46) this does not work
Line = Line.Substring(23)
Response.Write(Line & "<br>")
On the screen I can see all these modifications. Only I have problem to get rid of the fields at the end of each line. 'Line = Line.Remove(141, 46) this does not work
Line.Remove(110, count - 135) - this works but every line has different count and some of the fields are not deleted completely - couple words is left.
And finally I cannot write the file
IO.File.WriteAllLines("C:\temp\WaterPurge2.txt", Lines.ToArray()) -
this line of code writes the file in initial format without any modifications.
I wanted to use TextFieldParser Object but cannot do any modifications of the line there.