Ghostdog's VB duplicate remove ignore blanks?

December 31, 2010 at 04:31:08
Specs: Windows XP
Thank you Ghostdog for duplicate line removal VB script. It works very well, except that I have noticed it treats blank spaces at the enf of lines as being unique from duplicate lines without blank spaces. Is there a way to modify your script to ignore the blanks at the end of lines?Example:
Sub Folder Alpha
Sub Folder Alpha

I would like the program to treat these as duplicates and remove one (note spaces at end of lower line).
Thanks!!!! I pasted your original solution below:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\temp\test.txt"
Set objFile = objFS.OpenTextFile(strFile)
Set d = CreateObject("Scripting.Dictionary")
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Not InStr(strLine,"--------") >0 Then
If Not d.Exists(strLine) Then
d.Add strLine , 0
End If
End If
Loop
x=d.Items
For Each strKey In d.keys
WScript.Echo strKey
Next


See More: Ghostdogs VB duplicate remove ignore blanks?

Report •


#1
January 3, 2011 at 03:40:23
OK, I was able (eventually) to answer my own question: I "discovered" the RTrim function and applied it to trim spaces on the right side of the text as they were being read to strLine - I pasted the modification below. I also modifed the script to write to a specific file rather than echo to the screen. Thanks once again Ghostdog!

Const ForReading = 1
Const ForWriting = 2

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\Temp\doubleFree_raw.txt"
strFile_out = "c:\Temp\doubleFree.txt"

Set objFile = objFS.OpenTextFile(strFile, ForReading)
Set objFile_out = objFS.OpenTextFile(strFile_out, ForWriting, True)


Set d = CreateObject("Scripting.Dictionary")

Do Until objFile.AtEndOfStream
strLine = RTrim(objFile.ReadLine)
If Not InStr(strLine, "--------") >0 Then
If Not d.Exists(strLine) Then
d.Add strLine , 0
End If
End If
Loop

x=d.Items
For Each strKey In d.keys
objFile_out.WriteLine strKey
Next


Report •
Related Solutions


Ask Question