Text File Manipulation

Understand this is a 34 megabyte text file. It came from a unix server.
This is the code I am trying to run. As I write this the program continues to run and has been about 5 minutes.
I am trying to find a certain string in the file which would indicate that the line should be entirely deleted if the string exists in the line.

Let me know if I made any errors ok?

One other thing, when creating additional parameters to remove could you show an example just using "your query here" after the first If End IF
executed...IN other words how do I add additional queries to this to check for?

How do you remove blank lines using this method?

Does it matter the order you do them in?

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click

Dim strFile As String 'Name of the file

Dim strLine As String 'Data read

Dim textread As IO.TextReader 'Read data of file

Dim strOutputFileContents As String 'Accumulated content for the
output(File)

Dim strDealNumber As String = "***ITEM"

Dim pos As String

strFile =
IO.Path.Combine(IO.Path.GetDirectoryName(Application.ExecutablePath),
"C:/JJK0661.txt")

textread = IO.File.OpenText(strFile)

strLine = textread.ReadLine()

Do While IsNothing(strLine) = False

pos = InStr(strLine, strDealNumber)

If pos Then

strLine = Replace(strLine, strDealNumber, "")

End If

strOutputFileContents = strOutputFileContents + strLine + vbCrLf

Loop

Dim textwrite As IO.TextWriter 'Write data of file

textwrite = IO.File.CreateText(strFile)

textwrite.Write(strOutputFileContents)

textwrite.Close()

End Sub

Comments

  • Instr returns an integer. It's not a boolean.

    Francis

    :
    : pos = InStr(strLine, strDealNumber)
    :
    : If pos Then
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion