谁能帮我解释一下这个函数的作用啊  
function TObjModel.GetSubString(Line: String; ValueCount: Integer): String;
var fP,eP:Integer; vn:Integer;
    i:Integer;
    function WordCount(Line:String):Integer;   
    var i :Integer;
    begin
      Line:=' '+Line;
      Result:=0;
      for i := 1 to Length(Line)-1 do
      begin
        if (Line[i]=' ') and (Line[i+1]<>' ') then
          Result := Result+1;
      end;
    end;
begin
  vn:=0;
  fp:=1;
  ep:=0;
  Line:=Line+' ';
  if ValueCount>0 then
  for i := 2 to Length(Line)-1 do
  begin
    if (Line[i+1]<>' ')and(Line[i] = ' ') then
      Inc(vn);   //vn+1
    if vn=ValueCount then
    begin
      fp := i+1;
      Break;
    end;
  end;
  if ValueCount<WordCount(Line)-1 then 
    for i := fp+1 to Length(Line) do
    begin
      if Line[i] = ' ' then
      begin
        ep:=i;
        Break;
      end;
    end
  else
    ep := Length(Line);
  Result := Copy(Line,fp,ep-fp); 
end;

解决方案 »

  1.   

    大概意思就是根据ValueCount取字符串Line中的值,以空格分开的
    比如 Line := 'a b c';GetSubString(line,0) := 'a';
    GetSubString(line,1) := 'a';
    GetSubString(line,2) := 'a';如果ValueCount的值大于空格的数量,则返回整个字符串
      

  2.   

    GetSubString(line,0) := 'a';
    GetSubString(line,1) := 'a';
    GetSubString(line,2) := 'a';   ????能否说具体点啊 
      

  3.   

     function WordCount(Line:String):Integer;  
        var i :Integer; 
        begin 
          Line:=' '+Line; 
          Result:=0; 
          for i := 1 to Length(Line)-1 do 
          begin 
            if (Line[i]=' ') and (Line[i+1] <>' ') then 
              Result := Result+1; 
          end; 
        end; 
    这个函数的作用是返回字符串line中字串的个数(字串是用空格间隔的),如果字符串line=' a b c d'则返回值为4
      

  4.   

    GetSubString(Line: String; ValueCount: Integer): String;
    如果valuecount的值大于等于line子串个数减1,则返回值为字符串line;
    如果valuecount的值小于line子串个数减1,则返回值就是line中第valuecount+1个子串,是去掉空格的。
      

  5.   

    这个函数是不是写的太复杂了,完全可以改成这样
    function TForm1.GetSubString(Line: String; ValueCount: Integer): String;
    var
      i:Integer;
      str:TStrings;
    begin
      str:=TStringList.Create;
      str.Clear;
      ExtractStrings([' '],[],PChar(line),str);
      i:=str.Count;
      if valuecount>i-1 then
      begin
        result:=Line;
        Exit;
      end;
      result:=str.Strings[ValueCount];
    end;
      

  6.   


    写错了,^_^
    GetSubString(line,0) := 'a'; 
    GetSubString(line,1) := 'b'; 
    GetSubString(line,2) := 'c'; 
    WordCount是判断实际个数的,这个方法写的太罗嗦,用lovelymelon 的方法,明白了意图,自己写也是很容易的