首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

检测字符串时遇到的有关问题

2012-02-12 
检测字符串时遇到的问题利用下面语句欲检测字符串的左边第一个字符是不是F,若不是label1显示为“正确。”,若

检测字符串时遇到的问题
利用下面语句欲检测字符串的左边第一个字符是不是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;

[解决办法]

探讨
procedure TForm1.Button1Click(Sender: TObject);
begin
if LeftStr(trim(Edit1.Text), 1) <> 'F' then
label1.caption:='不正确。'
else
label1.caption:='正确。'
end;

[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
begin
if LeftStr(trim(Edit1.Text), 1) = 'F' then
label1.caption:='不正确。'
else
label1.caption:='正确。'
end;

热点排行