Delphi 计算一个字符串在另一个字符串中出现的次数
2022-12-26 09:18:37 作者:admin
本文整理自网络,侵删。
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注册与卸载系统服务
Delphi 10 seattle的android应用程序中使用参数启动服务
Delphi win32_diskdrive 硬盘 参数说明
Delphi 字符串操作之格式化
Delphi 封装的tidhttp get post 请求
Delphi中的各种文件类型介绍
tclientsocket和tserversocket用法
Delphi wmi 取硬件信息
Delphi 如何比较两个二维数组是否相等
Delphi显示gif动画简单方法
更多相关阅读请进入《Delphi》频道 >>
猜你喜欢
联络方式:
400-123-789
邮箱:xiachao@163.com
Q Q:12345678
微信公众号
微信二维码