Anyone know how I can....

Results 1 to 2 of 2

Thread: Anyone know how I can....

  1. #1
    Kamurika Guest

    Default Anyone know how I can.... for a text string in a text file and then put that text into an if statement, and read from the point after that text?

  2. #2
    Join Date
    Dec 1969

    Default top of head...

    &#060;%<BR>searchFor = "word" &#039 get the thing you are searching for...<BR><BR>Set FSO = Server.CreateObject("Scripting.FileSystemObject")< BR>Set inFile = FSO.OpenTextFile( Server.MapPath("yourFileName.txt") )<BR><BR>txt = ""<BR>foundAt = 0<BR>Do While Not inFile.atEndOfStream <BR>&nbsp; &nbsp; line = inFile.readLine<BR>&nbsp; &nbsp; If foundAt &#062; 0 Then &#039 already found the match!<BR>&nbsp; &nbsp; &nbsp; &nbsp; txt = txt & line<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; foundAt = InStr( 1, line, searchFor, vbTextCompare )<BR>&nbsp; &nbsp; &nbsp; &nbsp; If foundAt &#062; 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039 start with rest of this line...<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039 ...and foundAt works as a flag to keep appending lines!<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; txt = Mid( line, foundAt + Len(searchFor) )<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; End If<BR>Loop<BR><BR>Response.Write "&#060;PRE&#062;" & txt & "&#060;/PRE&#062;" &#039 a demo. only<BR>%&#062;<BR><BR>That will collect everything in the file past the point of the match. The match is NOT case sensitive. If you want it case sensitive, change vbTextCompare to vbBinaryCompare in the code.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts