var
   s:widestring;
begin
   s:='我';
   showmessage(inttostr(ord(s[1])));这样求出的是整个字的asc码,一个汉字用两个字节表示,怎么能求出他的第一个字节的asc码和第二个字节的asc码

解决方案 »

  1.   

    type
      TChnChar = string[2];function ChnCharToRTFCode(Ch: TChnChar): string;
    var
      C1, C2: Char;
      O1, O2: Byte;
      S: String;
    begin
      C1 := Ch[1];
      C2 := Ch[2];
      O1 := Ord(C1);  //第一个字节
      O2 := Ord(C2);  //第二个字节
      S := Format('%2X', [O1]) + Format('%2X', [O2]);
      Result := S;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(ChnCharToRTFCode('军'));
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      S: String;
    begin
      SetLength(S, 2);
      S[1] := Chr($BE);
      S[2] := Chr($FC);
      ShowMessage(S);
    end;
      

  2.   

    var
      S: WideString;
      SS: String;
    begin
      S := '我';
      SS := WideCharToString(PWideChar(S));
      ShowMessage(IntToStr(Ord(SS[1])));
    end;delphi7下通过
      

  3.   

    汉字2Unicodefunction TForm1.ChinaToUnicode(const aWideStr: WideString): string;
    var
      sUnicodeHex: string;
      i : integer;
    begin
      for i := 1 to Length(aWideStr) do
      begin
        sUnicodeHex := Format('%.4x', [Word(aWideStr[i])]);
        sUnicodeHex := Chr(StrToInt('$' + Copy(sUnicodeHex, 3, 2))) +
            Chr(StrToInt('$' + copy(sUnicodeHex, 1, 2)));
        Result := Result + sUnicodeHex;
      end;
    end;
      

  4.   

    我用Font Creator Program打开字体,里面有映射,如‘啊’的映射值为‘$554A’,我用上面各位的代码测试后,没有看到这个值。所以问问:字体里的映射对应的是什么??
      

  5.   

    参数说明:sMsg,原msg,acmsg拉收值,
    function HexToStr(const sMsg:string;var acMsg:array of char):integer;
    var
        iLen:integer;
    begin
        fillchar(acmsg,sizeof(acmsg),0);
        iLen:=length(sMsg);
        HexToBin(pchar(sMsg),acMsg,iLen);
        result:=0;
    end;
    //sMsg:='C4FABAC321BBB6D3ADB6A9D4C4B8C3D2B5CEF1';
    HexToStr(pchar(sMsg),acMsg);参数说明:sMsg,原msg,acmsg拉收值,
    function StrToHex(const sMsg:string;var acMsg:array of char):integer;
    var
        iLen:integer;
    begin
        fillchar(acmsg,sizeof(acmsg),0);
        iLen:=length(sMsg);
        bintohex(pchar(sMsg),acMsg,iLen);
        result:=0;
    end;
    ////sMsg:='您好!欢迎订阅该业务';
    StrToHex(pchar(sMsg),acMsg);超额完成任务,多给点分呀!!!!!!!!!!!!!!!!!