求一个算法 一个字符串(有字母,汉字,数字。标点符号,空格)等能够区别出来,只要是数字(一个)在这个数字前加A后面加B,汉字是前面加K后面加L。不知道说明白了吗。
我作的  汉字始终不可以,请大家帮帮忙。
例:
  字符串:=国外来的专业软件health123
转换后是:=K国LK外LK来LK的LK专LK业LK软LK件LAhBAeBAaBAlBAtBAhBA1BA2BA3B

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      str, tmp: string;
      i: integer;
    begin
      str := Edit1.Text;
      tmp := '';
      i := 1;
      while i <= Length(str) do
      begin
        if (Ord(str[i]) > 127) and (i < Length(str)) then
        begin
          tmp := tmp + 'K' + str[i] + str[i + 1] + 'L';
          Inc(i);
        end
        else if str[i] in ['0'..'9', 'a'..'z', 'A'..'Z'] then
          tmp := tmp + 'A' + str[i] + 'B';
        Inc(i);
      end;
      Edit2.Text := tmp;
    end;