只能用ord如果用if ord(str[i])>=127 then 的情况哪个汉字 会不对?

解决方案 »

  1.   

    汉字是两个字节,GB2312-80两个字节都大于127,
                  GBK只是前一个字节大于127,
      

  2.   

    以上是非Unicode码,
    如果用unicode会简单些, ASC码与汉字
    都是16位短整数,汉字高位不为0,非汉字高位为0
      

  3.   

    //判断字符是否是汉字  
    function IsHZ(ch:WideChar):boolean;
    var    
      i:integer;  
    begin    
    i:=ord(ch);    
    if( i<19968) or (i>40869) then     
     result:=false 
    else 
     result:=true;  
    end;  
    function TForm1.IsHZ(ch: Char): boolean;  
    begin    //返回值为 0 的时候为单字节字符,返回值为 1 的时候为多字节字符    
    if(ord(bytetype(ch,1))=1) then 
      result:=true    
    else 
      result:=false; 
    end;  
      

  4.   

    不用bytetype,只用ord的情况下if ord(str[i])>=127 then怎么改 可以最大限度正确呢
      

  5.   


    姸是GBK  为什么if ord(str[i])>=127 then  也可以判断
      

  6.   

    你用ord只能判断一个字节,而汉字两个字节,
    GBK的汉字,前一字节大于127,后一个字节不一定的。
      

  7.   

    function   CtoC(s:string):string; 
    var 
        i:integer; 
        ss:string; 
    begin 
    i:=1; 
    ss:= ' '; 
    while   i <=length(s)   do 
    if   ord(s[i])> 160   then   //中文字符 
    begin 
        ss:=ss+s[i]+s[i+1]; 
        i:=i+2; 
    end 
    else     //英文字符 
    begin 
        ss:=ss+s[i]; 
        i:=i+1; 
    end; 
    result:=ss; 
    end;
      

  8.   

    再如
    procedure TForm1.Button1Click(Sender: Tobject);
    var s:string;
    I,e,c:integer;
    begin
    s:=memo1.text;
    e:=0;c:=0;
    for I:=1 to length(s) do
    begin
    if (ord(s[I])>=33)and(ord(s[I])<=126) then
    begin
    inc(e);
    label1.caption:='英文字数:'+inttostr(e);
    end
    else
    if (ord(s[I])>=127) then
    begin
    inc(c);
    label2.caption:='中文字数:'+inttostr(c div 2);
    end;
    end;
    end;
      

  9.   

    因为我是判断是否有中文就好
    function IsChinese(_Source: string): Boolean;
    var   
    str:string; 
    i:integer; 
    flag : boolean;
    begin 
    str:=_Source; 
    flag:=false;
    for   i:=1   to   length(str)   do 
    begin 
    if ord(str[i])>=127 then
    begin 
    flag := true;
    break;
    end; 
    end;
    Result:= flag;
    end; 
      

  10.   


    厉害,佩服,学习如果我用WideString存放汉字和字母,是不是很容易区分出来汉字.
      

  11.   

    // 按你自己的代码修改了一下:function IsChinese(_Source: string): Boolean;
    var   
      str: string;  
      i: integer;  
    begin  
      str := _Source;  
      Result := false;
      for i:=1 to length(str) do  
      begin  
        if (ord(str[i]) > 127) and (ord(str[i+1]) > 127) then
        begin  
          Result := true;
          break;
        end;  
      end;
    end; 
      

  12.   


    能告诉我 哪些汉字 不能用这样  if ord(str[i])>=127 then 识别的吗?要用if (ord(str[i]) > 127) and (ord(str[i+1]) > 127) then
      

  13.   

      for i:=1 to Length(s) do
      begin
        //字符串中有中文字符?
        if ByteType(s,i)=mbLeadByte then
        begin
          //是的
          break;
        end;
      end;
      

  14.   

    使用下列函数:
    function ByteType(const S: string; Index: Integer): TMbcsByteType;  说明:显示字符串的一个字节,是否为单字节字符,双字节字符的第一个字节,或双字节字符的第二个字节。
      S字符串,Index为0时指定的第一个字节,为1时指定的第二个字节。
      如果系统不使用多字节系统(MBCS),ByteType总是返回mbSingleByte。否则,对于单字节时返回mbSingleByte,对于双字节的第一个字符返回mbLeadByte,对于双字节的第二个字符返回mbTrailByte。type TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);