views:

283

answers:

1

I have a loop that finds duplicate lines in a .ini file. I can happily find the duplicate lines, and write new lines to the file using FileSystemObject, however... I can't seem to find out how to delete the duplicate lines. What I want to do is delete the lines by line number as I have identified the relevant line number already.

Is there a native way to do this, or is it a case of rewriting the file minus the duplicate lines?

Any help is greatly appreciated.

Thanks.

My method of finding the duplicate entry is as follows:

  Do While Not file.AtEndOfStream
    intLineNumber = intLineNumber + 1
    strReadLineText = file.ReadLine
    If strSearchText <> "" And InStr(strReadLineText, strSearchText) > 0 Then
      session("message") = "Line Exists on " + Cstr(intLineNumber)
      '' # delete duplicate line...

    End If
  Loop
  file.Close()

You can see where my comment is, is where I wish to remove the line that is found.

+5  A: 

There are no built-in methods to do this in VBScript (or the intrinsic objects).

My vote would be to use string concatenation to accomplish this; i.e. instead of deleting lines, create a new file, line by line, and only append to the string if the line doesn't exist in the string you're building.

Alex Papadimoulis
I thought that's what I would have to do. Thank you for the quick feedback.
Tisch
+1: For the good answer. (Also: Upvoting Mr. TDWTF has made my (otherwise cruddy) day)
anschauung