德爾福2009年或更高版本(Unicode)的,有沒有內置函數或小程序的地方寫,會做一個合理高效的整個詞搜索,你提供定義這個詞的分隔符,如:德爾福有沒有一個有效的整詞搜索功能?
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;
其中:
Word: string; { is the Unicode string to search for }
Str: string; { is the Unicode string to be searched }
我只需要這個返回一個true或false值,如果「道」是的字符串中。
因爲標準的查找對話框具有「僅匹配整個單詞」作爲它的一個選項,所以在某處應該有一些東西。
這是如何實現的(或最好的)?
結論:
RRUZ的答案是完美的。 SearchBuf例程正是我所需要的。我甚至可以進入StrUtils例程,提取代碼並對其進行修改以符合我的要求。
我很驚訝地發現,SearchBuf不會先搜索該詞,然後檢查分隔符。相反,它一次遍歷字符串中的字符,尋找分隔符。如果它找到一個,那麼它檢查字符串和另一個分隔符。如果它沒有找到它,它會查找另一個分隔符。爲了提高效率,這非常聰明!
不錯!您現在將自己的解決方案發布在您自己的博客上,網址爲:http://theroadtodelphi.wordpress.com/2009/11/05,因爲我做了進一步的調查。感謝您提供的額外信息。 – lkessler 2009-11-06 04:54:48
'ExistWordInString('Delphi','Delphi'[soWholeWord,soDown]);'失敗。查看[SearchBuf soWholeWord意外輸出](http://stackoverflow.com/q/25877986/576719)。 – 2014-09-16 21:12:35