求一段字符串中字母的数量和非字母的数量

2018-11-27  本文已影响0人  netppp

procedure TForm3.Button1Click(Sender: TObject);

  var  a:string;

  m,n,i:integer;

begin

      a:='my ,name .is : tom?';

      m:=0;

      n:=0;

      for  i:=1  to  length(a)  do      //注意,STRING类型是从1开始计数的。

      begin

        if        (  a[i]  in ['a'..'z'] )    then      m:=m+1;

        if  not  (  a[i]  in ['a'..'z'] )    then  n:=n+1;

        //    if  not (  a[i]  in [' ',',','.',':','?'] ) then  m:=m+1;

        //      if    (  a[i]  in [' ',',','.',':','?'] ) then  n:=n+1;

      end;

              showmessage(inttostr(m));

            showmessage(inttostr(n));

end;

上一篇 下一篇

猜你喜欢

热点阅读