本文整理自网络,侵删。
function Occurrences(const Substring, Text: string): integer;var offset: integer;begin result := 0; offset := PosEx(Substring, Text, 1); while offset <> 0 do begin inc(result); offset := PosEx(Substring, Text, offset + length(Substring)); end;end;
{ Returns a count of the number of occurences of SubText in Text }function CountOccurences( const SubText: string; const Text: string): Integer;begin if (SubText = '') OR (Text = '') OR (Pos(SubText, Text) = 0) then Result := 0 else Result := (Length(Text) - Length(StringReplace(Text, SubText, '', [rfReplaceAll]))) div Length(subtext);end; { CountOccurences }
来源:https://cloud.tencent.com/developer/ask/217083https://stackoverflow.com/questions/5265317/delphi-count-number-of-times-a-string-occurs-in-another-string
相关阅读 >>
Delphi tstringdynarray 使用,分割字符串
Delphi开发firemonkey应用程序时无法打开窗体的解决
更多相关阅读请进入《Delphi》频道 >>