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:
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.
| Created 17 Jan 17 2004 |
Modified 07 Nov 2008 |