- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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;