这样
如果单词串是WordStr
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
begin
     pos:=ansipos(WordStr[index].text,s);
     len:=length(WordStr);
end;
    

解决方案 »

  1.   

    不好意思,错了,是
    procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
    begin
        pos:=ansipos(WordStr[index].text,s);//子串位置
        len:=length(s);//子串长度
    end;
      

  2.   

    是这个意思吗?
    例如:s:='I have a good time.'
          index:=4;
    然后求出‘good'的位置和长度。
      

  3.   

    学校课本上这种程序很多的。比如PASCAL上就有。
      

  4.   

    俺是新手,请多指教,^_^。
    procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
    var
      i,j:integer;
      flag:boolean;
    begin
      i:=0;
      flag:=true;
      if s[0]<>' '  then
      begin
        Index:=Index-1;
        flag:=false;
      end;
      i:=i+1;
      while i<=Length(s) and Index>0 do
      begin
        if s[i]<>' ' and flag=true then
        begin
          Index:=Index-1;
          flag:=false;
        end;
        i:=i+1
      end;
      if Index:=0 then Pos:=i
      else 出错;
      while s[i]<>' ' do
       i:=i+1;
      len:=i-Pos;
    end;
      

  5.   

    最主要一点是单词间可能有多个空格,要把单词之间的所有空格当成一个空格。我只提醒这么多,函数你自己写吧。Pascal书中有这样一个例子。
      

  6.   

    heifei的方法可能有错,如果一个字符串中有好几个相同单词就会出错。
    比如“I am single of single”,如果查第二个single就会出错的,呵呵。
    当然俺的解法可能错误更多。
    新手上路,请多指教。
      

  7.   

    贴段Delphi的Help:
    In traditional Pascal programming, all source code, including the main program, is stored in .PAS files. Delphi uses a project (.DPR) file to store the 搈ain?program, while most other source code resides in unit (.PAS) files. Each application梠r project梒onsists of a single project file and one or more unit files. (Strictly speaking, you needn抰 explicitly use any units in a project, but all programs automatically use the System unit.) To build a project, the compiler needs either a source file or a previously compiled DCU for each unit.其实也不仅仅是空格啦。3Q
      

  8.   

    sorry,新账号,只能加2分 :(