串中只有汉字,而不包括数字,字母,还有乱码什么的。。谢谢各位大大了!!

解决方案 »

  1.   

    下面是一个计算字符串中汉字个数的程序;楼主参考下;var ans : AnsiString;wis : WideString;sub : Integer; //汉字的个数Beginans := '盗版delphi';wis := WideString( ans );sub := Length( ans ) - Length( wis );End;
     
      

  2.   

    <<<<现炒现卖if length(edit1.Text)=length(widestring(edit1.Text)) then
    showmessage('edit1只有汉字')
      

  3.   

    //这个函数返回有斗筲个汉字
    function CalcUnicodeLen(const S: string):integer;
    var
      i,j:integer;
    begin
      j:=0;  For i:= 1 to Length(Trim(s)) do
      begin
        if ByteType(s,i)<> mbTrailByte then
          inc(j);
      end;
      Result := j;
    end;
      

  4.   

    一不小心贴错了,再来
    //这个函数返回有多少个汉字
    function CalcUnicodeLen(const S: string):integer;
    var
      i,j:integer;
    begin
      j:=0;  For i:= 1 to Length(Trim(s)) do
      begin
        if ByteType(s,i) = mbLeadBytethen
          inc(j);
      end;
      Result := j;
    end;