Delphi中计算字符串中分割符的总数【CountDelims】

函数代码

function CountDelims(const S, Delims: string): Integer;
var
  Idx: Integer; //loops thru all characters in string
begin
  Result := 0;
  for Idx := 1 to Length(S) do
    if IsDelimiter(Delims, S, Idx) then
      Inc(Result);
end;

测试

procedure TForm1.FormCreate(Sender: TObject);
begin
  caption:=CountDelims('a|b|c', '|').ToString;
end;

你可能感兴趣的:(delphi常用函数,字符串)