Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Find string and delete whats above.

Posted on 1999-06-28
Medium Priority
Last Modified: 2010-05-02

I need to find the string, "File Name" in a file
and delete everything that is above it.
I need to keep the initial string intact and everything
on its line and below.

Question by:vienna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Michelt earned 160 total points
ID: 1520236
If I understand Correcly  the following would work

Dim strtxt as string
Dim blnStrFound
open "c:\srcfile.txt" for input as #1
open "c:\Destfile.txt" for input as #1
do while not EOF(1)
   line Input 1,strtxt
   if instr(strtxt,"File Name") > 0 or blnstrFound = true then
       blnstrfound = true
       if instr(strtxt,"File Name") > 0 then      
           strtxt = mid$(strtxt,instr(strtxt,"File Name")
       end if
       print 2, strtxt
    end if
kill "C:\scrfile.txt"
name "c:\destfile.text" as "C:\scrfile.txt"
LVL 12

Expert Comment

ID: 1520237
Depending on the length of the file you can pull the whole thing into a string var in one shot.

FileSpec = "Source.Txt"
FileID = Freefile
buffer = space(FileLen(FileSpec))
OPEN FileSpec for BINARY AS #FileID
GET #FileID,,Buffer
FileID = FreeFile
Marker = Instr( Buffer, "File Name" )
if Marker > 0 then
  buffer = right( buffer, len( buffer ) - (Marker + 1))
  open FileSpec for binary as #FileID
  Put #FileID,, Buffer
End if



Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question