PosEx  这个涵数在那个单元里呢,我怎么在帮助里找不到这个函数!

解决方案 »

  1.   

    PosEx  unit 
    StrUtils 
    category 
    string handling routines 
    declaration 
     
     
    function PosEx(Str, Source : string, StartFrom : cardinal = 1): integer;
    description 
     
     
    Returns an integer specifying the position of the first occurrence of one string within another, where the search starts at a specified position. PosEx looks for the first complete occurence of Str in Source, beginning the search at StartFrom. If it finds one, it returns the character position in Source of the first character in Str as an integer value, otherwise it returns 0. PosEx also returns 0 if StartFrom is greater then Length(Source) or if StartPos is < 0
    example 
     
     
    var s : string;
        i : integer;

    s:='DELPHI PROGRAMMING';
    i:=PosEx('HI PR', s, 4);
    //i=1; 
     
    in real code 
     
     
    String Types in Delphi
    Understanding and managing string data types in Delphi's Object Pascal. Learn about differences between Short, Long, Wide and null-terminated strings.
    StrUtils
      

  2.   

    uses
      Classes,SysUtils;已经包含了,但还是出现以下错误
    [Error] unitFun.pas(42): Undeclared identifier: 'PosEx'
      

  3.   

    刚刚看了一下,D6的StrUtils.pas单元确实没有这个函数,看来是Delphi7新加的,你把下面的代码加进去看看:
    function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
    var
      I,X: Integer;
      Len, LenSubStr: Integer;
    begin
      if Offset = 1 then
        Result := Pos(SubStr, S)
      else
      begin
        I := Offset;
        LenSubStr := Length(SubStr);
        Len := Length(S) - LenSubStr + 1;
        while I <= Len do
        begin
          if S[I] = SubStr[1] then
          begin
            X := 1;
            while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
              Inc(X);
            if (X = LenSubStr) then
            begin
              Result := I;
              exit;
            end;
          end;
          Inc(I);
        end;
        Result := 0;
      end;
    end;
      

  4.   

    好像就是这个功能
    function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
    begin
      Result := pos(SubStr, copy(s, Cardinal, Length(s) - Cardinal + 1)) + Cardinal - 1;
    end;
    ///////////////////
    还有一个无关紧要的问题就是你上面写错了,不是SysUtils,而是StrUtils
      

  5.   

    不好意思写错了,改一下:
    function PosEx1(const SubStr, S: string; Offset: Cardinal = 1): Integer;
    begin
      Result := pos(SubStr, copy(s, Offset, Length(s) - Offset + 1)) + Offset - 1;
    end;