-
Apr 25th, 2006, 02:53 AM
#1
Thread Starter
New Member
how to search for a string inside a text file?
Hi there,
i want to search for a specific string inside a text file that i have, the problem is that the file contains HTML tags, so when i use , seems that ASP reads the text as code not as strings, so is there a possibilty to read this file and search for a string ?
i use the following code for reading:
VB Code:
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Server.MapPath("test.txt"), 2, false, -1)
do while not f.AtEndOfStream
Response.Write(f.ReadLine & vbCrLf)
loop
and this is a sample of the text file i am trying to search:
VB Code:
<TD class=IData align=middle bgColor=#ffffff><A
title="Isha is offered after the disappearance of the twilight until midnight."
onclick="MM_openBrWindow('HelpIsha_english.html','','width=540,height=320')"
href="javascript:;">[B]Isha[/B]</A></SPAN></TD></TR>
<TR>
<TD class=IslamicData align=middle bgColor=#ffffff>Tue</TD>
<TD class=IslamicData align=middle bgColor=#ffffff>4:38 </TD>
<TD class=IslamicData align=middle bgColor=#ffffff>6:04 </TD>
<TD class=IslamicData align=middle bgColor=#ffffff>12:36 </TD>
<TD class=IslamicData align=middle bgColor=#ffffff>4:14 </TD>
<TD class=IslamicData align=middle bgColor=#ffffff>7:08 </TD>
<TD class=IslamicData align=middle bgColor=#ffffff>8:29
</TD></TR></TBODY></TABLE><SPAN class=IslamicData>
what i want is to get the time values in the above snapshot, so what i am thinking is to search for the string that is bolded "Isha", and then try to get the times in a way that till now i dont know.
thanks in advance,
-
Apr 25th, 2006, 12:54 PM
#2
Hyperactive Member
Re: how to search for a string inside a text file?
VB Code:
dim fs, f,buffer, timestring
set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Server.MapPath("test.txt"), 2, false, -1)
Do while not f.AtEndOfStream
buffer = f.ReadLine
Response.Write(buffer & vbCrLf)
For i =1 to len(buffer)
if mid(buffer,i,len("bgColor=#ffffff>")) = "bgColor=#ffffff>" then
timestring = ""
Do until mid(buffer,i,1) = "<"
i = i + 1
timestring = timestring + mid(buffer,i,1)
Loop
'do whatever you need to with timestring here
End if
Next i
Loop
I hope that works (or helps) - pretty rough code.
KAZAR
The Law Of Programming:
As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
__________________________________
www.startingqbasic.co.uk
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|