Navigation: Main Page » Computer / Recreational / Science / Society / Television
 
Web N-N-A.com
         
Computer Groups Forum Index  »  Computer Programming Language - Visual Basic Miscellaneous  »  Find word in text file
Page 1 of 1    
Author Message
JaY
Posted: Mon Jul 27, 2009 4:04 am
Guest
I have been trying everything and cant seem to get this to work. I
really need help before I completely lose my mind.

Here is what I am trying to do:

I have an HTML file. I am trying to search for anywhere in the HTML
file for :

a href=""

I want to get what is in between the " " currently, extract it (logg
to string) and replace with contents of another string. Is this
possible? I thought I had it working and no luck. I really need this
soon. I have a project due and this is my last piece of the puzzle.
PLEASE HELP! ANYONE! HELP!
secondar@hotmail.com
Posted: Mon Jul 27, 2009 11:54 am
Guest
On Jul 26, 11:04 pm, JaY <jly...@optonline.net> wrote:
Quote:
I have been trying everything and cant seem to get this to work.  I
really need help before I completely lose my mind.

Here is what I am trying to do:

I have an HTML file.  I am trying to search for anywhere in the HTML
file for :

a href=""

I want to get what is in between the " " currently, extract it (logg
to string) and replace with contents of another string.  Is this
possible?  I thought I had it working and no luck.  I really need this
soon. I have a project due and this is my last piece of the puzzle.
PLEASE HELP!  ANYONE!  HELP!

JaY - If you are trying to change what is between the " " with a
string the same length, you can probably do it in the original file.

If you are trying to replace it with a different length string, you
will have to create a new file (read existing file & write the newly
modified file).

Basically, read the file in one byte at a time, searching for an "h".

When an "h" in encountered, read enough additional bytes to see if it
is an 'href="', if so, then read enough additional bytes to determine
if it is a string you want to replace.

If so, overwrite the file a byte at a time to replace the string.

If not, go back to reading the file a byte at a time.

Note - open mode = binary, access = read write.

In binary mode you can open two instances of the same file (just use
different file numbers) and can use one to cycle through a byte at a
time, and the other to do the look-ahead.
Gutless Umbrella Carrying
Posted: Mon Jul 27, 2009 9:24 pm
Guest
That is the complicated way. The easier way is to load the whole
file in to a string variable, and use instr to find each instance
of a href=" (single instance of the double quote), use instr again
with the first result as the starting point to find the next "
(double quote), then use mid to find what's between. You can then
replace that with either those starting and ending point and left
and right, or just use replace. If you're looking for multiple
instances, you can put your results in to a different string
variable, trim off what you've done in the original, and put the
while thing inside a do/loop.

Your way might well be faster, if the file is large.

"secondar@hotmail.com" <secondar@hotmail.com> wrote in
news:77bd0a80-e573-4ae4-b037-68404301d863@k1g2000yqf.googlegroups.c
om:

Quote:
On Jul 26, 11:04 pm, JaY <jly...@optonline.net> wrote:
I have been trying everything and cant seem to get this to
work.  I really need help before I completely lose my mind.

Here is what I am trying to do:

I have an HTML file.  I am trying to search for anywhere in the
HTML file for :

a href=""

I want to get what is in between the " " currently, extract it
(logg to string) and replace with contents of another string.
 Is this possible?  I thought I had it working and no luck.  I
really need thi
s
soon. I have a project due and this is my last piece of the
puzzle. PLEASE HELP!  ANYONE!  HELP!

JaY - If you are trying to change what is between the " " with a
string the same length, you can probably do it in the original
file.

If you are trying to replace it with a different length string,
you will have to create a new file (read existing file & write
the newly modified file).

Basically, read the file in one byte at a time, searching for an
"h".

When an "h" in encountered, read enough additional bytes to see
if it is an 'href="', if so, then read enough additional bytes
to determine if it is a string you want to replace.

If so, overwrite the file a byte at a time to replace the
string.

If not, go back to reading the file a byte at a time.

Note - open mode = binary, access = read write.

In binary mode you can open two instances of the same file (just
use different file numbers) and can use one to cycle through a
byte at a time, and the other to do the look-ahead.




--
Terry Austin

"Terry Austin: like the polio vaccine, only with more asshole."
-- David Bilek

Jesus forgives sinners, not criminals.
 
Page 1 of 1       All times are GMT
The time now is Fri May 24, 2013 7:04 pm