用Delphi自带的类: TParser,在Classes单元中定义:
代码如下:
_______________________________________________
function GetCount(S: string): Integer;
var
oString: TStream;
begin
Result := 0;
oString := TStringStream.Create(S);
with TParser.Create(oString) do
try
while(Token <> toEOF) do
begin
if Token = toSymbol then
Inc(Result);
NextToken;
end;
finally
Free;
oString.Free;
end;
end;