pos() copy() while()function GetFlagCount(const Flag,SourceString:string):integer; var tempstr:string; i:integer; begin tempstr:=Sourcestring; result:=0; while tempstr<>'' do begin i:=pos(flag,tempstr); if i>0 then begin inc(i); tempstr:=copy(tempstr,i+length(flag),length(tempstr)-length(flag)-i); end else begin showmessage('没有找到.'); break; end; end;end;
pos() copy() while()function GetFlagCount(const Flag,SourceString:string):integer; var tempstr:string; i:integer; begin tempstr:=Sourcestring; result:=0; while tempstr<>'' do begin i:=pos(flag,tempstr); if i>0 then begin inc(result);//----------------这个地方改下确一下。 ^_^ tempstr:=copy(tempstr,i+length(flag),length(tempstr)-length(flag)-i); end else begin showmessage('没有找到.'); break; end; end;end;
procedure GetCharCount(aStr: string;sStr: string;Site: integer;var Count: integer); //aStr需要统计的字符串,sStr要查找的字符串,Site从第几个字符开始查找,Count计数器 begin if Site<= Length(aStr) then if aStr[Site] = sStr then begin Count := Count + 1; Site := Site + 1; GetCharCount(aStr,sStr,Site,Count); end else begin Site := Site + 1; GetCharCount(aStr,sStr,Site,Count); end; end; 例如: var Count: integer; Count := 0; GetCharCount(edit1.Text,Edit2.Text,1,Count); ShowMessage(IntToStr(Count));
copy()
while()function GetFlagCount(const Flag,SourceString:string):integer;
var
tempstr:string;
i:integer;
begin
tempstr:=Sourcestring;
result:=0; while tempstr<>'' do
begin
i:=pos(flag,tempstr);
if i>0 then
begin
inc(i);
tempstr:=copy(tempstr,i+length(flag),length(tempstr)-length(flag)-i);
end
else
begin
showmessage('没有找到.');
break;
end; end;end;
copy()
while()function GetFlagCount(const Flag,SourceString:string):integer;
var
tempstr:string;
i:integer;
begin
tempstr:=Sourcestring;
result:=0; while tempstr<>'' do
begin
i:=pos(flag,tempstr);
if i>0 then
begin
inc(result);//----------------这个地方改下确一下。 ^_^
tempstr:=copy(tempstr,i+length(flag),length(tempstr)-length(flag)-i);
end
else
begin
showmessage('没有找到.');
break;
end; end;end;
//aStr需要统计的字符串,sStr要查找的字符串,Site从第几个字符开始查找,Count计数器
begin
if Site<= Length(aStr) then
if aStr[Site] = sStr then
begin
Count := Count + 1;
Site := Site + 1;
GetCharCount(aStr,sStr,Site,Count);
end
else begin
Site := Site + 1;
GetCharCount(aStr,sStr,Site,Count);
end;
end;
例如:
var
Count: integer; Count := 0;
GetCharCount(edit1.Text,Edit2.Text,1,Count);
ShowMessage(IntToStr(Count));
(length(str)-length(AnsiReplaceStr(str,'|',''))) div 2