procedure f(var stemp:string);
var
  i:integer;
begin
  i:=pos('\\',stemp);
  if i>0 then
  begin
    delete(stemp,i,1);
    f(stemp);
  end; 
end;

解决方案 »

  1.   

    procedure TFormChess.Button1Click(Sender: TObject);
    var
      S: string;
    begin
      S := 'f:\\fan\fa\\\fa\\\ttt\\\';
      while Pos('\\', S) > 0 do S := StringReplace(S, '\\', '\', [rfReplaceAll]);
      S := ExcludeTrailingPathDelimiter(S);
      Caption := S; //Show
    end;
      

  2.   

    function test(s: string): string;
    var
     s1:string;
     bfirst:boolean;
     i:integer;begin
      bfirst := true;
      for i:=1 to length(s) do
        if s[i]<>'\' then
          begin
            s1:=s1+s[i];
            bFirst := true;
          end
          else
            if bfirst then
            begin
              s1:=s1+s[i];
              bFirst:=false;
            end;   if s1[length(s1)]='\' then
         s1:=copy(s1,1,length(s1)-1);
       result := s1;
    end;