非2000平台可用机内码判断(肯定>128),前提是被判断的字符串中不含一般的字符,这样检索一遍可确定指定字节是汉字首,或汉字尾,或ascii码.
关于2000平台,据听说,装上jvm,可改变机器内码,也许不再适用(不是unicode,而是机内码).
大部分(99.9%)适用,复杂度o(n).

解决方案 »

  1.   

    前提是母串必须不包含半个汉字,再有是String or WideString.
      

  2.   

      str:='中文';
      if str[1]>chr(127) then  //str[1]是“中”字的一半
      begin
           showmessage('是中文的一半');
      end;
      

  3.   

    suny_2001:
    你的程序稍加改动,即可判断字首字尾.
    只需附加一个计数器,可能取值0,1,2,没检索一个字节,改变一次值.1为汉字头,0,2为汉字尾.
    ^_^给分吧!我认为早就解决了.
      

  4.   

    suny_2001(小鱼儿):
    可否帮一下我现在的问题贴子,有关postmessage的那个?谢谢. 
      

  5.   

    谢谢大家,谢谢pupil,鱼儿,怎样判断是汉字头,还是汉字尾?
      

  6.   

    参考一下:function GetHz0(s:string):string;
    var hz:string;i:integer;
    begin
      hz:='';
      for i:=1 to length(s) do
          begin
            if ByteType(s,i) <> mbLeadByte then    //单字节\//双字节的第二个字节
               begin
                   if trim(hz) = '' then
                      begin
                          hz := s[i]+ #13#10;
                      end
                   else
                      begin
                          if i = Length(s) then
                             begin
                                 hz := hz  + s[i];
                             end
                          else
                             begin
                                 hz := hz  + s[i]+ #13#10;  //  ' ';//
                             end;
                      end;
               end
            else      //双字节的第一个字节
               begin
                   if trim(hz) = '' then
                      begin
                          hz := s[i];
                      end
                   else
                      begin
                          hz := hz + s[i];
                      end;
               end;
          end;
        GetHz0:=hz;
    end;
      

  7.   

    procedure TForm1.Button2Click(Sender: TObject);
    var str,str1:string;
     I:INTEGER;
     ishead:boolean;
    begin
       str:='aa中dd文a';
       ishead:=true;
       str1:='';
      FOR  i:=1 to length(str) do
      begin
      str1:=str1+str[i];
      if str[i]>chr(127) then
      begin
           if not ishead then
           begin
                ishead:=true;
                showmessage('汉字尾');
           end
           else
           begin
                ishead:=false;
                showmessage('汉字头');
           end;
      end;
      end;
    end;
      

  8.   

    楼上的同志做得对阿
    用ASCII吗
    大雨127的是汉字啊
      

  9.   

    我已经解决了这个问题,用PWideString来代替String就可以了,当然,响应的就是PWideChar了