我想在一个textfile里面读数据,textfile中的内容是这样的:
string1  string2
string1  string2
等等
其中string1 和string2 之间有两个空格,各个string1的长度不是一样的,string2后面还有一个回车符。我想从文件中读出这两个串,用readln/read怎么办?要是一个字符一个字符的读,最好给出程序!谢谢!

解决方案 »

  1.   

    用tstrings简单一些
    var
      Stringlist : TStrings ;
      I : INteger ;
      s ,s1,s2 : String ;
      Index : INteger ;
    begin
      Stringlist := TStringlist.create ;
      Stringlist.loadformfile('c:\temp.txt'); 
      for I := 0 to Stringlist.count -1 do
      begin
        s := Stringlist[i] ;
        Index := pos('  ',s);
        if index >0 then
        begin
         s1 := copy(s,1,index);
         delete(s,1,index);
         s2 := trim(s);
         //do other things
        end ;
      end ;
    end;
      

  2.   

    比如你String1和String2的最大长度分别为10,20,那么
    var
      f : TextFile;
      string1 : string[10];
      string2 : string[20];
    begin
      AssignFile(f,YouTxtFile);
      Reset(f);
      try
        while not Eof(f) do
        begin
          Readln(f,string1,string2);
          You Op
        end;
      finally
        CloseFile(f);
      end;
    end; 你试试,不知可行否
      

  3.   

    楼上的,好像你的程序只是蒋前十个字符读到string1,而将其余的读到string2而已。不行吧!