Results 1 to 2 of 2

Thread: how to search for a string inside a text file?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    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:
    1. dim fs, f
    2.   set fs=Server.CreateObject("Scripting.FileSystemObject")
    3.   Set f = fs.OpenTextFile(Server.MapPath("test.txt"), 2, false, -1)
    4.  
    5. do while not f.AtEndOfStream
    6.  Response.Write(f.ReadLine & vbCrLf)
    7. loop

    and this is a sample of the text file i am trying to search:
    VB Code:
    1. <TD class=IData align=middle bgColor=#ffffff><A
    2.                   title="Isha  is offered after the disappearance of the twilight until midnight."
    3.                   onclick="MM_openBrWindow('HelpIsha_english.html','','width=540,height=320')"
    4.                   href="javascript:;">[B]Isha[/B]</A></SPAN></TD></TR>
    5.               <TR>
    6.                 <TD class=IslamicData align=middle bgColor=#ffffff>Tue</TD>
    7.                 <TD class=IslamicData align=middle bgColor=#ffffff>4:38 </TD>
    8.                 <TD class=IslamicData align=middle bgColor=#ffffff>6:04 </TD>
    9.                 <TD class=IslamicData align=middle bgColor=#ffffff>12:36 </TD>
    10.                 <TD class=IslamicData align=middle bgColor=#ffffff>4:14 </TD>
    11.                 <TD class=IslamicData align=middle bgColor=#ffffff>7:08 </TD>
    12.                 <TD class=IslamicData align=middle bgColor=#ffffff>8:29
    13.               </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,

  2. #2
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: how to search for a string inside a text file?

    VB Code:
    1. dim fs, f,buffer, timestring
    2.   set fs=Server.CreateObject("Scripting.FileSystemObject")
    3.   Set f = fs.OpenTextFile(Server.MapPath("test.txt"), 2, false, -1)
    4.  
    5. Do while not f.AtEndOfStream
    6.  
    7. buffer = f.ReadLine
    8. Response.Write(buffer & vbCrLf)
    9.  For i =1 to len(buffer)
    10.           if mid(buffer,i,len("bgColor=#ffffff>")) = "bgColor=#ffffff>"  then
    11.             timestring = ""
    12.                     Do until mid(buffer,i,1) = "<"
    13.                             i = i + 1
    14.                             timestring = timestring + mid(buffer,i,1)                            
    15.                     Loop
    16.                    'do whatever you need to with timestring here
    17.          
    18.           End if
    19.   Next i
    20.  
    21. 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
  •  



Click Here to Expand Forum to Full Width