if memo1.Lines.IndexOf('terry')=-1 then showmessage('没有这个字符串') else showmessage('该字符串位于第'+inttostr(memo1.Lines.IndexOf('terry')+1)+'行');
楼上的哥哥您发了个错误,希望您平时写程序不是这样,而是因为回答问题才写错的 var i:longing; begin i:=memo1.Lines.IndexOf('terry'); if i=-1 then showmessage('没有这个字符串') else showmessage('该字符串位于第'+inttostr(i)+'行'); end;这个问题虽小,但如果按您的写法第一效率低,第二因为有两个地方私用'terry'所以容易出现bug
showmessage('没有这个字符串')
else
showmessage('该字符串位于第'+inttostr(memo1.Lines.IndexOf('terry')+1)+'行');
var i:longing;
begin
i:=memo1.Lines.IndexOf('terry');
if i=-1 then
showmessage('没有这个字符串')
else
showmessage('该字符串位于第'+inttostr(i)+'行');
end;这个问题虽小,但如果按您的写法第一效率低,第二因为有两个地方私用'terry'所以容易出现bug