请教各位大侠:
delphi如何判断是中文还是英文??
先谢了!!!

解决方案 »

  1.   

    function IsChsChar(Str: string): Boolean;
    var
      i: Integer;
    begin
      Result := False;
      for i := 0 to Length(Str) - 1 do
      begin
        if Ord(Str[i]) > $7F then  {if Ord(Str[i]) > 127 then}
        begin
          Result := True;
          Break;
        end;
      end;
    end;
      

  2.   

    英文就那么几个字母,逐个判断ASC就可以了
      

  3.   

    我是用
    ord 的方法判断的。pStr: PChar;pStr :='这是一个中英文混合的字符串';while pStr <> #0 do
    begin
      if Ord(pStr^) < 128 then
      begin
        showmessage('english');
        Inc(pStr);
      end else
      begin
        showmessage('chinese');
        Inc(pStr, 2);
      end;end;
      

  4.   

    ndicates whether a byte in a string is a single byte character, the first byte of a double byte character, or the second byte of a double byte character.UnitSysUtilsCategoryMBCS utilitiesfunction ByteType(const S: string; Index: Integer): TMbcsByteType;DescriptionCall ByteType to determine the type of the byte specified by the Index parameter, where 0 specifies the first byte in S, 1 specifies the second byte, and so on.If the system is not using a multi-byte character system (MBCS), ByteType always returns mbSingleByte. Otherwise, ByteType returns mbSingleByte if the indicated byte represents a complete character in S, mbLeadByte if it represents the first byte of a double byte character, and mbTrailByte if it represents the second byte of a double byte character.Note: No checking is done to ensure that Index is less than the length of S. It is the caller's responsibility to ensure that Index is not out of bounds.
    下面是统计字符串中汉字和英文的个数function TfrmDBGridSendMsg.CountNumberLong(const Value: string): TPoint;
    var
      i: Integer;
    begin
      Result.x := 0; //英文
      Result.y := 0; //汉字
      for i := 1 to Length(Value) do
      begin
        if ByteType(Value, i) = mbSingleByte then //是英文
          Result.x := Result.x + 1
        else if ByteType(Value, i) = mbLeadByte then //是汉字
          Result.y := Result.y + 1;
      end;
    end;