In Delphi 2009 or later (Unicode), are there any built-in functions or small subroutines written somewhere that will do quite efficient whole word searches, where you provide delimiters that define that word, for example:
function ContainsWord(Word, Str: string): boolean; const { Delim holds the delimiters that are on either side of the word } Delim = ' .;,:(){}"/\<>!?[]'#$91#$92#$93#$94'-+*='#$A0#$84;
Where:
Word: string; { is the Unicode string to search for } Str: string; { is the Unicode string to be searched }
I only need this to return true or false if "Word" is in the string.
There must be something for this somewhere, because in the standard search dialog box there is “Match the whole word” only as one of its options.
How is this usually (or better) implemented?
Output:
RRUZ's answer was perfect. The SearchBuf procedure was exactly what I needed. I can even go into the StrUtils routine, extract the code and modify it according to my requirements.
I was surprised to find that SearchBuf does not search the word first, and then checks the delimiters. Instead, it goes through the string characters one at a time in search of a separator. If he finds one, then he checks the string and the other delimiter. If he does not find it, he searches for another delimiter. For efficiency, it is very smart!
lkessler
source share