Text Search

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

Search

 

Search DelphiForFun.org only

Support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

 

Search DelphiForFun.org only

 

 

Here is a simple program to search a text file  for a user specified string. 

The substring search function, Pos, is used to perform the basic search of each line of the input text file.  

If the "Case sensitive" checkbox is checked, the search is performed "as is".  If "Case Sensitive" is not checked, then both the input line and the input string are converted to upper case before the "Pos" search is performed.

If "Whole words only" is checked a call is made to function IsWord   which returns true two conditions are met:  

  • The position before the first letter of the search string is a delimiter or 0 (i.e. the string begins at the beginning of the line). 
  • The position after the last letter of the search string is a delimiter or past the end of the line (i.e. the string ends at the end of the line). 

 

One more check box, "Show hits only" ,  allows user  to display only the lines with matches or  to display the entire input file with matched strings  highlighted.   In order to highlight the matches strings, a TRichEdit is used.  The matched strings are selected using Selstart and SeLength properties and setting SelAttributes  to make the font style bold.  The same technique could also apply color or other style properties to matches.   One trick is used  to highlight multiple occurrences of the search string in the displayed input line - each occurrence is replaced by  non-displayable characters in the working copy of the line before the next search is performed.

  

Download source

Download executable

                                        

Created 17 Jan 17 2004  

Modified 07 Nov 2008

 

              


  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2009, Gary Darby    All rights reserved.