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 三种方式读取txt文本文件

Delphi listview 实现进度条显示

Delphi与sql server存储过程编程详解

Delphi xe3中使用tidftp的示例

Delphi中的unicode转换

Delphi复制文件时,如何显示进度条

Delphi tms web core webmemo 横竖滚动条

Delphi 图像分割

Delphi xe中将正则表达式tregex的使用

Delphi tstringlist 排序 customsort

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



打赏

取消

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

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

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

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

评论

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