Delphi删除连续重复的字符并且保留一个

//删除字符串连续重复的符号
function StrPosCount(subChar: Char; var source: string): string;
var
  pStart, p: PChar;
  Str: string;
  start, index, tempCount: Integer;
begin
  Str := source;
  while True do
  begin
    index := Pos(StringOfChar(subChar, 2), Str);
    if (index <> 0) then
    begin
      start := index;
      tempCount := 0;
      p := Pchar(Str);
      inc(p, index);
      while p^ = subChar do
      begin
        Inc(p);
        tempCount := tempCount + 1;
      end;
      Delete(Str, index + 1, tempCount);
    end
    else
    begin
      Break;
    end;
  end;
  Result := Str;
end;
posted @ 2021-11-02 16:40  图图雷  阅读(215)  评论(0)    收藏  举报