Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete duplicate line of data in a text file

Status
Not open for further replies.
Jan 30, 2002
44
CA
Hi Everyone,

Does anyone have a sample code in VB 6 to delete duplicate line of data in a text file.

For example, my text file contains:

this is a dog
this is a cat
this is a mouse
this is a dog

I want to delete duplicate line 'this is a dog.

Thanks everyone.

VBNewbie
 
Sort the file then compare each line to the previous line.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Create a dictionary object then add each line as a key with a value of 1. When you get done, the keys collection will be the lines without duplication. Alternatively you can make the value be the line number. Then you can put them back into original order.
 
Hi Dr JavaJoe

can you please write some code for me to do that. I assume I would use the File System Objectto open and read the file. Which function would I use to compare each line?

Thanks
 
You could use Regex to determine a loose match, but it is overkill if you want an identical match.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top