例如文本文件中有这样一行:1   2345.324     4345.567   500   62   123.899怎么把里面的500读出来?(请给出源代码)本来想通过POS('空格数',STR)结合COPY函数来实现,可发现每行的空格数不一样,有朋友说通过定位数字的方法来实现,可具体怎么做又没讲,恳请各位帮忙。

解决方案 »

  1.   

    for i := 1 to 3 do
      STR := Trim(Copy(STR, Pos(' ', STR), Length(STR)));
    STR := Copy(STR, 1, Pos(' ', STR) - 1);
      

  2.   

    s1:string;
    line:string;
    s:strings;
    lineposition,currentposition,len:integer;
    s:=tstringlist.create;
    s.loadfrom('文本文件');
    lineposition:=0;
    whild lineposition<s.count do
    begin
        currentposition:=1;len:=length(s[lineposition]);line:=' ';
       while currentposition<len do
            begin
                while s[lineposition][currentposition]=' ' do inc(currentposition);
                whild ss[lineposition][currentposition]<>' ' do 
                                  begin
                                      line:=line+s[lineposition][currentposition];
                                     inc(currentposition);
                                  end;
                  if trim(line)'='500' then showmessage('found');
             end;
    s.free;
    在网吧,不知s.count是否正确,但strings有类似的属性!
        
      

  3.   

    s1:='  2345.324     4345.567   500   62   123.899  ';
    s2:='500';
    s3:=strpos(Pchar(s1),PChar(s2));
    s3:=copy(s3,1,length(s2));
      

  4.   

    谢谢各位.另:reedseutozte(haha)怎么把问题具体化了,我只是举个例子,呵呵.