• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Delete a text from a .txt file using vb6.0

I need to search for a string in the .txt file and then delete it... any easy way to do this?

thanks
0
Carol2009
Asked:
Carol2009
1 Solution
 
RimvisCommented:
Hello Carol2009,

Check this:

Edit and manipulate text files
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6454&lngWId=4

Regards,

Rimvis
0
 
Carol2009Author Commented:
That was for ASP (Active Server Pages), VbScript (browser/client side)  .. i am interst only on visual basic v6.0

Thanks
0
 
Patrick MatthewsCommented:
Hello Carol2009,

1. A specific string, or a string meeting a particular pattern/criteria?
2. All instances of the string, or just the first?
3. Is the text file large or small?

Regards,

Patrick
0
 
RimvisCommented:
The code for VB 6.0 is neatly identical. Just add type declarations like his:

Dim objFSO as FileSystemObject

0
 
VBClassicGuyCommented:
Something like (excuse my use of Implicit variable declaration):
s% = Freefile
t% = Freefile
Open "C:\MyFile.txt" for Input As #s%   'source (original) file
Open "C:\MyFilteredFile.txt" For Output As #t%   'target (with string deleted) file
While Not EOF(s%)
   Line Input #s%, txt$
   Replace(txt$, "Unwanted string", "")
   If Len(txt$) Then Print #t%, txt$
Wend
Close
Kill "C:\MyFile.txt"
Name "C:\MyFilteredFile.txt" As "C:\MyFile.txt"
   
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now