Einzelnen Beitrag anzeigen

EgonHugeist

Registriert seit: 17. Sep 2011
187 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#53

AW: Anzahl eines Zeichens im String ermitteln

  Alt 13. Jul 2018, 09:45
@Uwe

Schaut gut aus! No a bizzl kürzer:
Delphi-Quellcode:
function CharCount(const S: string; C: Char): Cardinal;
var
  P, PEnd: PChar;
begin
  Result := 0;
  P := Pointer(S);
  if P = nil then Exit;
  PEnd := P + PLongInt(NativeUInt(P) - SizeOf(LongInt))^;
  while P < PEnd do begin
    Inc(Result, Ord(P^ = C));
    Inc(P);
  end;
end;
  Mit Zitat antworten Zitat