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;
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;
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;
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;