我尝试递归替换找到的文本,但我无法让它工作。这将只替换每个“文本”之前的 1 个“a”字符,但我想替换文本之前的所有“a”字符
//Declared recursive function
function OneLine(s:WideString):WideString;
begin
s:=StringReplace(s,'atext', 'text', [rfReplaceAll]);
if (Pos(Result,'atext')>0) then
begin
//XMLstring:=Result;
s:=OneLine(XMLstring);
end
else
begin
Result:=XMLstring;
end;
end;
//--Here begins program
Var
t:string
Begin
//exaple of text
//we need replace all 'a' before 'text' only
t:='aaHaaatextaaaatextHHaatextHHaaaa';
//call custom recursive function
t:=OneLine(t);
ShowMessage(t);
End.
我需要替换这个:'aaHaaatextaaaatextHHaatextHHaaaa'
最终文本应如下所示:'aaHtexttextHHtextHHaaaa'