比方说LISTBOX1列表框中有如下字符:1112,1113,1122,1123,对比列表框字符是否符合变量{设变量为1123456},我们可以这样实现if (Form1.ListBox3.Items.IndexOf(STR)>0) then {但列表框字符跟变量必须全一致才>0}现在我想实现的是列表框字符只要一部份相同条件就成立如为11就能>0,也就是像POS函数那样只要符合父串其中一部份就能大于0,请大大们指教下,最好给下代码
解决方案 »
- 同在一局域网内,有的客户端能正常运行,有的不能正常运行
- [重金求问]想通过程序将一幅图像变成一个线描图
- 文件保存问题
- 控件编写问题,急需,分数可以按照你的要求
- 求助哪位高手帮我修改一下极速浏览器一个小地方
- 为什么我在MDI中不能用showmodal来显示我创建的的子窗口!!!
- 谁有打印报表的资料
- 1stclass中outlookbar的使用方法
- 怎样去掉form上的最大化,和最小化的图标,以及不能使form最大和最小化!急!
- 再问一个小问题,在Delphi中如果跳出过程,用什么语句?分数不多但很容易得,快来抢分啊
- delphi的activex form资源释放的问题,十万火急
- 求:DELPHI下二维码源码或控件,请发到邮箱。
unit Unit11;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm11 = class(TForm)
lst1: TListBox;
btn1: TButton;
edtSourceStr: TEdit;
edtLength: TEdit;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure SelItems(const ASourceStr: string; const Len: Integer);
{ Private declarations }
public
{ Public declarations }
end;var
Form11: TForm11;implementation{$R *.dfm}procedure TForm11.SelItems(const ASourceStr : string; const Len : Integer);
var
i : integer;
str : string;
begin
for i := 0 to lst1.Items.Count - 1 do
begin
str := Copy(lst1.Items[i], 0, Len);
if Pos(str, ASourceStr) > 0 then
lst1.Selected[i] := True;
end;
end;procedure TForm11.btn1Click(Sender: TObject);
begin
lst1.ClearSelection;
SelItems(edtSourceStr.Text, StrToInt(edtLength.Text));
end;procedure TForm11.FormCreate(Sender: TObject);
begin
lst1.Clear;
lst1.Items.Add('1112');
lst1.Items.Add('1113');
lst1.Items.Add('1122');
lst1.Items.Add('1123');
lst1.MultiSelect := True; edtSourceStr.Text := '1123456';
edtLength.Text := '4';
end;end.
var
I: Integer;
begin
Result := -1;
if (S = '') or (Items = nil) then Exit; for I := 0 to Items.Count - 1 do begin
if Pos(S, Items[I]) > 0 then begin
Result := I;
Exit;
end;
end;
end;
嗯,pos就搞定了
感谢提供,但是列表框里的数据太多,用FOR很慢,要等10秒才有结果,有没有最快的方法
则可以排序后再二分查找定位,这样会快非常多倍。。