有一个字符中由符号,英文和中文组成,我想提取中文,中文是连在一起的,不必考虑分开的情况:

akdfla:?ag中文kajdl
则取出为:
中文

解决方案 »

  1.   

    中文属于双字节结构,取出第一和第二字节,他们的Ascii值大于127属于中文,也可以为unicode字节
      

  2.   

    ?asc("A")
     65 
    ?asc("在在职")
    -11046 
    ?Asc("AAAA")
     65 
    ?Asc("在")
    -11046 
    ?Asc("“")
    -24144 
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        str: string;
        i: integer;
        temp : string;
    begin
        str := 'i love you 中国';
        temp := '';
        i := 0;
        while i < length(str) do
        begin
            while IsDBCSLeadByte(byte(str[i])) do
            begin
                temp := temp + widestring(str[i]+str[i+1]);
                i := i+2;
            end;
            inc(i);
        end;
        showmessage(temp);
    end;
      

  4.   

    Procedure TForm1.Create(Sender : TObject);
    var
      S_String : String;
    begin
      S_String := 'ddd中文ddsd';
      Self.Caption := Copy(S_String,4,4);
    end;
      

  5.   

    procedure TForm1.Button12Click(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
    begininc(c);
    copy(s,i,length(s));
    showmessage(copy(s,i,length(s)));
    label2.caption:='中文个数:'+inttostr(c div 2);
    end;
    end;end;
      

  6.   

    coreblood(菜码) IORILI(眼镜@_@) 两位的方法都好用。
      

  7.   

    coreblood(菜码) :我的不是以空格分隔的,不行啊!!!

     IORILI(眼镜@_@) :我不是要个数,我是要把中文提出来
      

  8.   

    function GetChinese(const ss:string):string;
    var i,len,st:integer;
    begin
       result:='';
       i:=1;
       len:=length(ss);
       while (i<=len) and (not IsDBCSLeadByte(ord(ss[i]))) do
         inc(i);
       if i<=len then
       begin
        st:=i;
        while (i<=len) and (ord(ss[i]) and $80=$80) do
          inc(i);
        result:=copy(ss,st,i-st);
       end;
    end;
      

  9.   

    coreblood(菜码) 的代码可以的,不管有没有空格,你可以测试一下。
      

  10.   

    感谢zzllabc(龙)!也感谢coreblood(菜码)!
    结账!!
      

  11.   

    function TForm1.DistillCN(const Value: string): string;
    var
      i:integer;
    begin
      i:=1;
      while i< length(Value) do   //最后一个字符不需要检查
      begin
        if ord(Value[i])>$80 then
        begin
          Result:=Result+Value[i]+Value[i+1];
          inc(i,2);
        end
        else
          inc(i);
      end;
    end;