Searching for strings efficiently in text files

Results 1 to 2 of 2

Thread: Searching for strings efficiently in text files

  1. #1
    Fuzion Guest

    Default Searching for strings efficiently in text files

    Hi,<BR>I have a text file in the following format<BR>###&#060;some text&#062;<BR>i.e.<BR>001text1<BR>003othertext<BR> 002text2<BR>The file is about a megabyte in size, and I don&#039;t think it&#039;s efficient to read the whole file for every request. I also can&#039;t change the format of the text file, that&#039;s the way it will be, and it&#039;ll be modified a lot. What would be the best way to get text2 if the user enters 002?<BR>Also the numbers are not in order. I thought about putting it in an access database, and checking for changed data using fc, then updating the changed data but I&#039;m not sure if that&#039;s the best way to do it.

  2. #2
    Join Date
    Dec 1969

    Default Write a custom component...

    You&#039;ll never do this efficiently in VBS code.<BR><BR>Oh, you *could* do a ReadAll to get it all into one big string and then search in the string using INSTR, but strings in VBS are *always* Unicode, so the entire text has to be translated from your current language to Unicode. <BR><BR>With a component, you could keep the text in a buffer and then just do a *very* fast search in the buffer.<BR><BR>How many times will you "hit" this looking for a line before the text file will be updated again? If only a few hundred, try the component approach. If more, use a process that updates a DB table (or even throw the prior table away and just recreate it...simpler and maybe even more efficient). If fewer than a dozen an hour, go ahead and use VBS and the string search. It&#039;s ugly, but who cares?

Posting Permissions

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