delphi 取出一个字符在字符串出现的次数


本文整理自网络,侵删。

 
function GetStrCounts(ASubStr, AStr: string): Integer;
var
  i: Integer;
begin
  Result := 0;
  i := 1;
  while PosEx(ASubStr, AStr, i) <> 0 do
  begin
    Inc(Result);
    i := PosEx(ASubStr, AStr, i) + 1;
  end;
end;

//PosEx在StrUtils单元




方法2:20190920 补充
function StrPosCount(subs:string;source:string):integer;
var
Str : string;
begin
Result := 0;
str := source;
while Pos(Subs,Str)<>0 do
begin
Delete(Str,Pos(Subs,Str),Length(Subs));
Inc(Result);
end;
end;

相关阅读 >>

Delphi 运行带参数的程序等待其并获取结果

Delphi中的各种文件类型介绍

Delphi操作access数据库

Delphi 获取剪切板图像

Delphi 读取流 image1 stream 加载到image2 timage 对象

截取程序的网络封包(Delphi hook api)

Delphi gdi+ 实现简单画图

Delphi读取文本文件的最后一行

Delphi 试试带参数的 exit

Delphi x秒生成大量垃圾字符

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



打赏

取消

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

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

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

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

评论

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