怎样才能判断出一个变量中的字符串是否是汉字?

解决方案 »

  1.   

    var s:string;
    if length(s)=2 then s:='汉字' else s:='字符'
      

  2.   

    可以判断字符的ascii码,大于128的就是汉字
      

  3.   

    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 utilitiesDelphi syntax:function ByteType(const S: string; Index: Integer): TMbcsByteType;C++ syntax:extern PACKAGE TMbcsByteType __fastcall ByteType(const AnsiString S, int Index);DescriptionCall ByteType to determine whether a specified byte in a string is a single-byte character, the first byte of a multibyte character, or one of the trailing bytes.AnsiString is the string that contains the byte in question.Index identifies the byte for which you want to know the byte type. Bytes are numbered from 1.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 a subsequent byte of a multibyte 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.