Einzelnen Beitrag anzeigen

Dax
(Gast)

n/a Beiträge
 
#29

Re: StringReplace und doppelte Zeichen

  Alt 24. Dez 2007, 21:01
Delphi-Quellcode:
function ReduceMultiples(const s: string; c: char): string;
var
  pe, pr, pc: PChar;
  i: integer;
begin
  if s = 'then exit;
  SetLength(result, Length(s));
  pc := @s[1];
  i := 0;
  while pc^ <> c do begin
    Inc(pc);
    Inc(i);
  end;
  if i > 0 then begin
    Move(s[1], result[1], i);
    pe := @s[i+1] + Length(s) - i;
    pr := @result[i+1];
  end else begin
    pe := @s[1] + Length(s);
    pr := @result[1];
  end;
  while pc <> pe do begin
    while (pr^ = pc^) and (pc^ = c) do
      Inc(pc);
    pr^ := pc^;
    Inc(pr);
    Inc(pc);
  end;
  SetLength(result, pr - @result[1]);
end;
Gehts so?
  Mit Zitat antworten Zitat