先定义了这个变量MyStrList: TStringList;
然后用mystrlist.add()往里面加了很多文件名,如abc.exe、xyz.exe等等,
如果里面有重复的文件名,如abc.exe、xyz.exe、abc.exe,怎样让它只保留一个呢?
事先不知道里面有多少个重复的文件名在线等待!谢谢!
然后用mystrlist.add()往里面加了很多文件名,如abc.exe、xyz.exe等等,
如果里面有重复的文件名,如abc.exe、xyz.exe、abc.exe,怎样让它只保留一个呢?
事先不知道里面有多少个重复的文件名在线等待!谢谢!
解决方案 »
- unidac 如何对数据的插入和更新
- 简单,白痴问题。oracle数据库,要在A库中建一个表tableA的结构和另一个B库中的tableB一样。最佳解决办法。DX相助!
- 关于ADOQUERY中使用SQL语句的问题,帮忙改错,急
- WebBrowser 问题,屏蔽来自页面的关闭
- vclskin控件使用的问题
- 如何让你的应用程序独占整个界面,而不让用户随便使用系统?
- 如何设一个日期类型的字段的值为空或为零???
- 关于窗口变化的几个问题
- 在DLL中的一个函数中,怎样把这堆东西返回到主程序中啊?
- 找圆角边的按钮控件,效果类似FlatStyle的FlatButton(可惜不能设置圆角),谢谢。高分!先到先得~~~
- 三层系统中客户端向服务端提交数据的问题,欢迎大侠们近来讨论
- DELPHI既然不支持多继承,不是应该写成多条单继承才对吗,如果TC=CLASS(TA,TB)
这样Add的时候就会将同名的忽略掉。
大写是为了避免Abc.exe和ABC.exe。
用Append和Add差不多。
我干脆把我的目的和源代码让你看看吧,帮我改一下,谢谢了,有点乱!
不好意思!
目的是想找出字符串中所有扩展名为.exe的文件名,并把它们保存下来,但这段代码总是有重复的文件名,不知是哪里错了,请帮我修改一下。谢谢!(在线等待)
procedure TForm1.Button1Click(Sender: TObject);
begin
MyStrList:=TStringList.Create;
str:='abcsafdj=abc.exe abckli=xyz.exe kjl;jl=abc.exe';
while Pos('.exe',str)>0 do
begin
p:=Pos('.exe',str)-1;
s:='.exe';
mychar:=copy(str,p+5,1);
if (mychar='"') or (mychar=' ') or (mychar='>') then
begin
while (p>0) and not (Str[p] in ['/','\','=','"']) do
begin
s:=Str[p]+s;
Dec(p);
end;
MyStrList.Duplicates := dupIgnore;//这条好像没起作用。
MyStrList.Add(S);
Delete(Str,1,p+5);
end
else
delete(str,1,p+5);
end;
for i := 0 to myStrList.Count - 1 do
MyStrList[i] := ChangeFileExt(MyStrList[i], '[A].exe');
memo1.Lines:=mystrlist;//最后显示在MEMO里,很多重复的
end;
你需要添加:
SL.Sorted := True;
begin
MyStrList:=TStringList.Create;
MyStrList.Duplicates := dupIgnore;//这条好像没起作用。
str:='abcsafdj=abc.exe abckli=xyz.exe kjl;jl=abc.exe';
while Pos('.exe',str)>0 do
begin
p:=Pos('.exe',str)-1;
s:='.exe';
mychar:=copy(str,p+5,1);
if (mychar='"') or (mychar=' ') or (mychar='>') then
begin
while (p>0) and not (Str[p] in ['/','\','=','"']) do
begin
s:=Str[p]+s;
Dec(p);
end;
MyStrList.Add(S);
Delete(Str,1,p+5);
end
else
delete(str,1,p+5);
end;
for i := 0 to myStrList.Count - 1 do
MyStrList[i] := ChangeFileExt(MyStrList[i], '[A].exe');
memo1.Lines:=mystrlist;//最后显示在MEMO里,很多重复的
end;
試試吧!
procedure TForm1.Button1Click(Sender: TObject);
begin
MyStrList:=TStringList.Create;
MyStrList.Duplicates := dupIgnore;
MyStrList.Sorted := True;
str:='abcsafdj=abc.exe abckli=xyz.exe kjl;jl=abc.exe';
while Pos('.exe',str)>0 do
begin
p:=Pos('.exe',str)-1;
s:='.exe';
mychar:=copy(str,p+5,1);
if (mychar='"') or (mychar=' ') or (mychar='>') then
begin
while (p>0) and not (Str[p] in ['/','\','=','"']) do
begin
s:=Str[p]+s;
Dec(p);
end;
MyStrList.Add(S);
Delete(Str,1,p+5);
end
else
delete(str,1,p+5);
end;
for i := 0 to myStrList.Count - 1 do
MyStrList[i] := ChangeFileExt(MyStrList[i], '[A].exe');
memo1.Lines:=mystrlist;//最后显示在MEMO里,很多重复的
end;
var
MyStrList: TStringList;
str, s, myChar: string;
p: Integer;
i: INteger;
begin
MyStrList := TStringList.Create;
MyStrList.Duplicates := dupIgnore;
MyStrList.Sorted := True;
str := 'abcsafdj=abc.exe abckli=xyz.exe kjl;jl=abc.exe';
while Pos('.exe', str) > 0 do
begin
p := Pos('.exe', str) - 1;
s := '.exe';
mychar := copy(str, p + 5, 1);
if (mychar = '"') or (mychar = ' ') or (mychar = '>') then
begin
while (p > 0) and not (Str[p] in ['/', '\', '=', '"']) do
begin
s := Str[p] + s;
Dec(p);
end;
MyStrList.Add(S);
Delete(Str, 1, p + 5);
end
else
delete(str, 1, p + 5);
end;
MyStrList.Sorted := False;
for i := 0 to myStrList.Count - 1 do
MyStrList[i] := ChangeFileExt(MyStrList[i], '[A].exe');
memo1.Lines := mystrlist; //最后显示在MEMO里,很多重复的
end;
标题栏是debugger exception notification
下面还有很多内容:
project1.exe raised exception class EStringListerror with message
'Operation not allowed on sorted list'……
什么意思?怎么解决?
不仅很多重名的显示出来了,而且有很多名字都不全,比如abc.exe
会出现c.exe这种情况,实际上没有c.exe这个文件名。