一个字符串,取出其中的字段。

ztiger 2004-04-06 09:28:54
(1)str='project eof'
(2)str='14.txt 12.txt 151.txt'

如果str中有.txt,则将14.txt,12.txt,151.txt分别取出。
...全文
29 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ztiger 2004-04-06
  • 打赏
  • 举报
回复
非常感谢二位的帮忙!

但是这个str里的数据是不确定的。我在其他帖子上看到一个用stringlist的,可以解决这个问题。http://expert.csdn.net/Expert/topic/2655/2655738.xml?temp=9.939212E-02

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
S: string;
SL: TStringList;
begin
S := '111 222 333 444 555';
SL := TStringList.Create;
ExtractStrings([' '], [], PChar(S), SL);
for i := 0 to SL.Count - 1 do
showmessage(SL.Strings[i]);
SL.Free;
end;
zhangheaaa 2004-04-06
  • 打赏
  • 举报
回复
if Pos('.txt', str) > 0 then
begin
pos1:=Pos(' ',str);
str1:=copy(str,1,6);
str:=copy(str,7,length(str));
str2:=copy(str,1,6);
str:=copy(str,7,length(str));
str3:=copy(str,1,6);
end;
aiirii 2004-04-06
  • 打赏
  • 举报
回复
var str, s: string;
I: integer;
begin
str :='14.txt 12.txt 151.txt';
i := Pos('.txt', str);
while i > 0 do
begin
s := copy(str, 1, i +4);
delete(str, 1, i+4);
s := Trim(s);
showmessage(s);
i := Pos('.txt', str);
end;
end;

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧