我就是不想用 pos 做循环来实现
有没有其它方法呢
本来想用 strrscan 
但不会用总报错

解决方案 »

  1.   

    procedure TForm2.Button1Click(Sender: TObject);
    var
       sString,dString:String;
       i,ePos,Counter:integer;
    begin
       sString:=edit1.Text;
       Counter:=0;
       for i:=Length(sString) downto 1 do
       begin
          if copy(sString,i,1)='*' then
          begin
             Counter:=Counter+1;
             if  Counter=2 then
             begin
                ePos:=i;
             end;
          end;
       end;
       dString:=Copy(sString,1,ePos);
       showmessage(dString);
    end;
      

  2.   

    function GetMySubStr(aString: string; SepChar: string): string;
    var
      i: Integer;
      StrLen: Integer;
      Num: Integer;
      j:array of integer;
    begin
      StrLen:=Length(aString);
      Num := 0;
      setlength(j,strlen);
      for i:= 1 to StrLen do
        if Copy(aString,i,1) = SepChar then
        begin
          j[Num]:=i;
          Num:=Num + 1;
        end;
     result:=copy(astring,1,j[Num-2]);
     end;调用
      showmessage(GetMySubStr(Edit1.text,'*'));
      

  3.   

    function AMethod(s: string): string;
    var
    a: PChar;
    begin
      Result := Copy(s, 0, Length(s) - 1);
    a := StrRScan(PChar(Result), '*');
      if a <> nil then
    a^ := #0;
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
      Edit3.Text := AMethod(Edit2.Text);
    end;
      

  4.   

    chechy(chechy) 兄方法不错,我改了改,更符合题意,嘻嘻
     var
    a: PChar;
    begin
      Result := Copy(s, 0, Length(s) - 1);
      a := StrRScan(PChar(Result), '*');
      if a <> nil then begin
        inc(a);
        a^ := #0;
      end;
    end;