怎么判断某个字符串中指定字符的个数

iranjn 2004-12-10 03:54:02
问题同上.如1*2*3*中可以输出*有3个.其实方法听多的,我想找一个较为简便的方法
...全文
160 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellolongbin 2004-12-10
  • 打赏
  • 举报
回复
这个方法不错
chinaandys 2004-12-10
  • 打赏
  • 举报
回复
更简单的:

var
S,tmp:string;
i:Integer;
begin
S:='1*2*3*';
i:=length(S);
tmp:=stringreplace(S,'*','',[rfReplaceAll]);
i:=i-length(tmp);
end;
chinaandys 2004-12-10
  • 打赏
  • 举报
回复
更简单的:

var
S,tmp:string;
i:Integer;
begin
S:='1*2*3*';
i:=length(S);
tmp:=stringreplace(S,'*','',rfReplaceAll);
i:=i-length(tmp);
end;
constantine 2004-12-10
  • 打赏
  • 举报
回复
如果你连这个都懒,那么
用StringReplace

strTemp: String ;
str : String;
strTemp := '1*2*3*4*5*';
str := StringReplace(strTemp, '*', '', [rfReplaceAll]);
showmessage(inttostr(Length(strTemp)-Length(str)));
ghchen 2004-12-10
  • 打赏
  • 举报
回复
var
i,cnt:integer
Str:String;
begin
cnt:=0;
str := '1*2*3*';
for i:=1 to length(str) do
if str[i]=ord('*') then inc(cnt);
end
nhconch 2004-12-10
  • 打赏
  • 举报
回复
var
i,cnt:integer
Str:String;
begin
cnt:=0;
str := '1*2*3*';
for i:=1 to length(str) do
if str[i]=ord('*') then inc(cnt);
end
lvsongbo 2004-12-10
  • 打赏
  • 举报
回复
var
i,j:integer
Str:String;
begin
j:=0;
for i:=1 to length(1*2*3*) do
begin
str:=copy(1*2*3*,i,1);
if str='*'then
inc(j);
end;
end
constantine 2004-12-10
  • 打赏
  • 举报
回复
简单的没有,无非就时循环找咯,还有什么,没有听过.

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧