Editing a text file

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hello,

I'm hoping someone can help with what I percisive as a problem
(hopefully easily resolved by one of you)! I need to edit a text
programmatically to remove certain sections. Basically, I receive a text
file from a supplier which is in fact a complexe listing of parts. However,
intermixed in the parts listing is a user data section (this is what I must
delete).

The Text file is of the following structure

(Part number: 1234527
Assembly: abc

(User data
(some info
(some more info
(

and then the next part is listed. The problem is that the User data section
can vary in size (3-4 or more lines). The only thing that I have managed to
notice as a pattern is the the section always begins by the "(User data"
section and always end by a multitude of spaces and a bracket on an
independant line.
The text file is located c:\Parts\listing.txt. I would like to have a
function that would look for each User data section in the txt and delete
them all and once finished saved the txt as AbbrigedListing.txt

I greatly appreciate any help and thank you in advance for the input!

Daniel P
 
If you are comfortable with VBA coding, you could:
- Open the text file for input.
- Open another file for output.
- InputLine
- Print # for the lines you want output.
- Close both
- Kill the original.
- Name the new one as the old one.
 
But how can I selectively delete the require section? How can I detect it's
presence and then delete it or if I understand your tought, omit it when I
create my new version?

Daniel
 
Use Instr() to detect where the bad section starts, and Instr() to detect
the line where the bad data ends. If they are whole lines, just don't output
them to your new file. If they are partial lines, use Left() and Mid() to
piece together the parts you do want, and Print # that.
 
Back
Top