OnButton1Click().
var
tempstr,hello:String;
i,j:integer;
begin
     j:=1;
     hello:='hello';
     for i:=1 to length(hello) do
     begin
          if((ord(hello[i])and $01111111)>$00111111)then
          begin
             tempstr[j]:=hello[i];
             inc(j);
          end;
     end;
     memo1.lines.add(tempstr);
end;
在memo1中什么都没有输出,tempstr中并没有等于'hello',这是怎么
回事啊?

解决方案 »

  1.   

    你的if条件处理语句永远不会被执行  当然tempstr就为空了
      

  2.   

    我想原因在这里:
    tempstr[j]:=hello[i];
    上一句改成tempstr:=tempstr+hello[i];看看。或者在一开始用setlength(tempstr,40)给它设置一个长度。
      

  3.   

    highbury(海布里) 说得对,我试过了,你的if没有被执行,原因就在于你这句
    if((ord(hello[i])and $01111111)>$00111111)then有错
    因为ord(x)返回的是一个八位的数。而你的十六进制有八个,就是一个三十二位的数。所以不行。应该缩小为两个十六进制:if((ord(hello[i])and $01)>$00)then具体的代码如下:
    var
    tempstr,hello:String;
    i:integer;
    begin
         hello:='hello';     tempstr:='';
         for i:=1 to length(hello) do
         begin
              if((ord(hello[i])and $01)>$00)then
              begin
                 tempstr:=tempstr+hello[i];
              end;
         end;
         memo1.Text:=tempstr;
    end;
      

  4.   

    应该综合7838205(我爱Delphi) 和linzhengqun(linzhengqun)两的方案
      

  5.   

    你的目的是不是判断是不是汉字的问题
    如果使用系下面的条件试试:
    //...
      hello:='hello';
      tempstr := '' ;
      for i:=1 to length(hello) do
      begin
       if((ord(hello[i])and $10000000)=$1000000)then
         Continue;
       tempstr:= tempstr+ hello[i];
      end;
    //...