Re: string comparision in a file

From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 07/21/04


Date: Wed, 21 Jul 2004 18:33:46 GMT

rakesh wrote:

> Hi,
> I have a requirement in which I need to search a string in a file
> stored on a harddisk. String which needs to be searched would be
> stored in a file with delimiter as new line character. some of the
> ways of doing this are
>
> 1. Read each line and do string compare immediately.
> 2. Read each line, add each string into a stl vector and search for
> the given string using stl bineary_search algorithm.
>
> It would be helpful if someone could give me comparison of which would
> be the best method among the above mentioned ways of handling
> searching. I would also welcome any other better of handling searching
> string in a file.
>
> Thanks,
> Rakesh.

If your system supports muli-tasking (multi-threading or whatever),
you could have one task reading lines into a buffer while another
task searches a given line.

This would assume that reading a line takes longer than searching it
and there is considerable overhead time when reading a line (such as
hard-drive start-up time, seeking time, etc.). Although these
timings usually only appear when the number of lines to read in
is huge; or the I/O overhead times are really slow.

Hmmm, why do things simple when you can have some fun making them
more complex? ;-)

-- 
Thomas Matthews
C++ newsgroup welcome message:
          http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq:   http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
          http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
     http://www.josuttis.com  -- C++ STL Library book


Relevant Pages

  • Re: String searching and lienar optimization
    ... There are *lots* of things known about pattern matching. ... string: "fjwkrjweoriosdaicfosdifidoiasosifosdifosdfio" for example.. ... Can this problem be posed suitable lfor linear optimization? ... What I am trying to do is to structure a string searching ...
    (sci.math.num-analysis)
  • RE: Oject value changing in a loop
    ... Sub zString_FindGeneral(ByRef IFindThis As String, ... ByRef IFmRow As Long, ByRef IFmCol As Integer, ByRef IToRow As Long, ByRef ... ' OFoundQty is the number of cells found containing the IFindThis string. ... 'Lines A, D, E work when searching one or multiple worksheets ...
    (microsoft.public.excel.programming)
  • Re: Parameter Query Form Problem
    ... Dim stDocName As String ... This is what I used to make my query, its was a Microsoft support site. ... controls on the form so it can run the query. ... Combo Box for searching Customer Name ...
    (microsoft.public.access.formscoding)
  • Re: Fastest way to search text file for string
    ... I'm searching a text file for a given string -- ... "I don't want to load the entire file into physical memory" ... Not stuck, that is the requirement. ...
    (microsoft.public.dotnet.languages.csharp)

Loading