Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

search a string and display several lines

I have to search for a string in a text file(5 to 6 mega)and I am required to display 4 lines before and 13 lines each time the string is found.Please can some body help.I do not know VB.The only thing I know is record macro in Excel.
Thanks
[250 byte] By [emam] at [2007-11-11 10:26:25]
# 1 Re: search a string and display several lines
dim a as string
dim i as integer
open file for input as #1
do until eof(1)
i=i+1
input #1, a
if instr(1,a,"MyText") then
exit do
end if
loop
close #1
dim list as listbox
dim tmp as string
dim j as integer
open file for input as #1
do
j=j-1
input #1,tmp
if j=i-4 then
dim k as integer
list.additem tmp
for k=0 to 17
list.additem tmp
next
exit do
end if
loop
msgbox "DONE!"
close#1
Amahdy at 2007-11-11 17:22:34 >
# 2 Re: search a string and display several lines
maybe need some adjustment , or line +/- ... this is the general idea but haven't tested the code .
Amahdy at 2007-11-11 17:23:45 >