检测字符串时遇到的问题
利用下面语句欲检测字符串的左边第一个字符是不是F,若不是label1显示为“正确。”,若是label1显示为“不正确。”
procedure TForm1.Button1Click(Sender: TObject);
var
F:string;
begin
if LeftStr(Edit1.Text, 1)<>F then
label1.caption:='正确。'
else
label1.caption:='不正确。'
end;
结果不论字符串的左边第一个字符是不是F,label1均显示为“正确。”检测失败。
[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
if LeftStr(Edit1.Text, 1)<>'F' then
label1.caption:='正确。'
else
label1.caption:='不正确。'
end;
[解决办法]