小弟初学,代码很乱,不好意思。以下是我的代码,目的是找出str中所有扩展名为.bat的文件名,如本例中应是abcde.bat和poiut.bat。但我写得这段代码只能找出第一个.bat的文件名abcde.bat,后面一个就不行了,怎样才能把它们都找出来并且都保存下来呢?注意事先不知道有多少个.bat,本例有2个只是举的例子。
急啊!求各位快帮忙吧!
非常感谢!
var
Form1: TForm1;
str: string;
MyChar: string;
p, pTmp: Integer;
L: Integer;
pLen: Integer;
MyStrList: TStringList;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyStrList:=TStringList.Create;
str:='abcdefghi=abcde.bat qwertyioj/poiut.bat';
L:=Length(str);
p:=pos('.bat',str);
pTmp:=p;
MyChar:=copy(str,p+4,1);
if (MyChar='"') or (MyChar=' ') or (MyChar='>') then
begin
while (pTmp>0) and (str[pTmp]<>'/') and (str[pTmp]<>'\') and
(str[pTmp]<>'=') and (str[pTmp]<>'"') do
begin
Dec(pTmp);
end;
if (str[pTmp]='/') or (str[pTmp]='\') or
(str[pTmp]='=') or (str[pTmp]='"') then
begin
pLen:=(L-pTmp)-(L-(p+3));
MyStrList.Add(copy(str,pTmp+1,pLen));
delete(str,1,p+3);
end;
end;
end;
急啊!求各位快帮忙吧!
非常感谢!
var
Form1: TForm1;
str: string;
MyChar: string;
p, pTmp: Integer;
L: Integer;
pLen: Integer;
MyStrList: TStringList;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyStrList:=TStringList.Create;
str:='abcdefghi=abcde.bat qwertyioj/poiut.bat';
L:=Length(str);
p:=pos('.bat',str);
pTmp:=p;
MyChar:=copy(str,p+4,1);
if (MyChar='"') or (MyChar=' ') or (MyChar='>') then
begin
while (pTmp>0) and (str[pTmp]<>'/') and (str[pTmp]<>'\') and
(str[pTmp]<>'=') and (str[pTmp]<>'"') do
begin
Dec(pTmp);
end;
if (str[pTmp]='/') or (str[pTmp]='\') or
(str[pTmp]='=') or (str[pTmp]='"') then
begin
pLen:=(L-pTmp)-(L-(p+3));
MyStrList.Add(copy(str,pTmp+1,pLen));
delete(str,1,p+3);
end;
end;
end;
解决方案 »
- 读取MP3文件的ID3v2标签、程序耗尽内存资源
- field xxx cannot be modified 问题
- :=WebBrowser.Document as IHTMLDocument2;为什么有的页面取不出里面的内容,比方说www.126.com登陆进去后,用这个接口什么也取不到
- Dll调用的问题,头疼了都,谢谢帮忙看看
- 关于treeview连接数据库的问题 急!!!! 代码已贴出!
- 谁能提供这样一个grid控件给我的,100分!
- Ras分机拨号的问题,急!急!急!
- 那位高手用過 BDE API..給我們菜鳥講解講解好碼!
- TADOQuery和SQL2000有冲突吗?
- 浏览硬盘中的图形文件,将此图形文件保存于SQL数据库中?
- 我在调用DLL时为什么报错
- 关于ADO?
begin
MyStrList:=TStringList.Create;
str:='abcdefghi=abcde.bat qwertyioj/poiut.bat';
while(pos('.bat',str)>0) do//加一个循环就可以了/////////////
begin
p:=pos('.bat',str);
L:=Length(str);
pTmp:=p;
MyChar:=copy(str,p+4,1);
if (MyChar='"') or (MyChar=' ') or (MyChar='>') then
begin
while (pTmp>0) and (str[pTmp]<>'/') and (str[pTmp]<>'\') and
(str[pTmp]<>'=') and (str[pTmp]<>'"') do
begin
Dec(pTmp);
end;
if (str[pTmp]='/') or (str[pTmp]='\') or
(str[pTmp]='=') or (str[pTmp]='"') then
begin
pLen:=(L-pTmp)-(L-(p+3));
MyStrList.Add(copy(str,pTmp+1,pLen));
// delete(str,1,p+3);
end;
end;
delete(str,1,p+3);//避免死循环,如abcde.bat_qwertyioj
end;//////////
end;
谢谢!请你再告诉我,如果要在EDIT里显示这些文件名,应该在哪里加代码?如果要在别的地方调用这些文件名呢?
请快再告诉我这两个问题,搞定了马上加分。
谢谢!
谢谢!请你再告诉我,
1、如果要在EDIT或MEMO里显示这些文件名,应该在哪里加代码?
2、如果要在别的地方调用这些文件名呢?
请快再告诉我这两个问题,搞定了马上加分。
谢谢!
好像不行啊,还是只能显示出第一个文件名来!!!
急啊!!!
是啊,还是那些乱七八糟的问题,不过好像就差一点点了。
快告诉我啊!!
我刚才试了
memo1.Lines:=mystrlist;
edit1.Text:=mystrlist.Text;还是只能显示出第一个文件名,
是不是后面的根本没有存进去,还是显示方法不对?
拜托了!
如果得到第二個值可以:
Edit1.Text := mystrlist.strings[1];(第一個為strings[0]);
字符串最后要加一个空格,否则字符串没有规律了
yang6130(2.5G) 告诉你的方法是正确的在单击事件最后加一句
memo1.Lines := MyStrList;祝你好运! ^_^