Delphi的RichEdit中search的反向问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 18:16:41
如何简便的做到在Delphi的RichEdit或者Memo中search某字段时,反向search?
我目前只知道使用最笨的办法,就是从头search到当前处,选择出最近的一个!
有没有更好的Delphi自带的function等等吗?

给你一个函数,从右边开始POS子字符串

function TMemoSearch.RPos(Search, Str: string): Integer;
var
Start, Ending : Boolean;
NotFound : Boolean;
begin
NotFound := False;
repeat
Result := Length( Str ) - Length( Search ) + 1;
while ( Result > 0 ) do begin
if Copy( Str, Result, Length( Search ) ) = Search then
Break;
Dec( Result );
end;

if ( Result > 0 ) and ( frWholeWord in Options ) then begin
Start := ( Result = 1 ) or ( not ( Str[ Result - 1 ] in FChars ) );
Ending := ( Result + Length( Search ) - 1 = Length( Str ) ) or
( not ( Str[ Result + Length( Search ) ] in FChars ) );

if not ( Start and Ending ) then begin
Str := Copy( Str, 1, Result );
Result := 0;
end;
if St