Delphi 计算一个字符串在另一个字符串中出现的次数


本文整理自网络,侵删。

 
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/217083
https://stackoverflow.com/questions/5265317/delphi-count-number-of-times-a-string-occurs-in-another-string

相关阅读 >>

Delphi disable_uac_vista

Delphi md5加密算法

Delphi判断文件是否正在被使用

Delphi 用idhttp打开网页或下载文件时如何显示进度

Delphi ip编辑控件

Delphi 调用外部 dll 中的函数(1. 早绑定)

Delphixe4 版本中,已针对移动平台 引入了 arc 模型

Delphi运行时的问题,cannot focus a disabled or invisible window!

Delphi 判断文件类型函数

Delphi中httpencode使用注意事项

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...