var
  F: TextFile;
  S: string;
  MyArray: array[1..6] of string;
  i,j:integer;
begin
  if OpenDialog1.Execute then            { Display Open dialog box }
  begin
    AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
    Reset(F);    Readln(F, S);                        { Read first line of file }
    j:=1;
    for i:=1 to Length(s) do
    begin
      if s[i]<>'' then
        MyArray[j]:=MyArray[j]+s[i]
      else
        Inc(j);
    end;
    CloseFile(F);
  end;
end;

解决方案 »

  1.   

    var
      Cstr, Lstr: string;
      F1: TextFile;
    begin
      AssignFile(F1, 'c:\c.txt');
      Reset(F1);  while not eof(f1) do
      begin
        readln(f1,Lstr);    while Pos(' ', Lstr) > 0 do
        begin
          Cstr := copy(Lstr, 0, pos(' ', Lstr) - 1);
          Lstr := copy(Lstr, pos(' ', Lstr) + 1, length(Lstr));
          showmessage(Cstr);
        end;    if Trim(Lstr) <> '' then
        begin
          Cstr := Lstr;      showmessage(Cstr);
        end;
      end;
      closefile(f1);
    end;
      

  2.   

    我的几个子过程:………
     Procedure SubfromStr(Const Str_T:String;Var 
                          Str0,Str1:String);OverLoad;
                      //Str_T:带分解的字符串  
                      //Str0:Str_T中空格分格的第一个子串
                      //Str1:剩下的子串   Procedure SubfromStr(Const Str_T:String;Delimiter:Char;Var 
                          Str0,Str1:String);OverLoad;                  //Str_T:带分解的字符串  
                      //Delimiter:分隔符
                      //Str0:Str_T中空格分格的第一个子串
                      //Str1:剩下的子串  Implementation//截取子串
     Procedure SubfromStr(Const Str_T:String;Var Str0,Str1:String);
      Var
         Str:String;
         Str_Pos1,Str_Pos2:Integer;
         Str_Start,Str_num,Str_pos:Integer;
      begin
         str:=trim(Str_t);
         Str_pos1:=Pos(' ',Str);
         Str_pos2:=Pos(',',Str);
         Str_pos:=min(Str_pos1,Str_pos2);
         if(Str_Pos=0)then
            Str_pos:=Max(Str_pos1,Str_pos2);     if(Str_Pos=0)then
         begin
            Str0:=Str;
            Str1:='';
         end
         Else
         begin
            Str_Start:=1;
            Str_Num:=Str_Pos-1;
            Str0:=copy(str,Str_Start,Str_Num);
            Str_Start:=Str_Num+2;
            Str1:=Copy(Str,Str_Start,length(Str));
         end;
      end;//截取子串,重载
      Procedure SubfromStr(Const Str_T:String;Delimiter:Char;Var Str0,Str1:String);
      Var
         Str:String;
         Str_Pos1,Str_Pos2:Integer;
         Str_Start,Str_num,Str_pos:Integer;
      begin
         str:=trim(Str_t);
         Str_pos:=Pos(Delimiter,Str);     if(Str_Pos=0)then
         begin
            Str0:=Str;
            Str1:='';
         end
         Else
         begin
            Str_Start:=1;
            Str_Num:=Str_Pos-1;
            Str0:=copy(str,Str_Start,Str_Num);
            Str_Start:=Str_Num+2;
            Str1:=Copy(Str,Str_Start,length(Str));
         end;
      end;End.