请指教!

解决方案 »

  1.   

    delphi写的,转成java吧
    function GetHz(qm, wm: Integer): String;
    begin
    Result := Chr(160+qm)+Chr(160+wm);
    end;
    procedure GetQWCode(HZ: string; var Q, W: Word);
    begin
    Q := Byte(HZ[1]) - $A0; 这是区码
    W := Byte(HZ[2]) - $A0; 这是位码
    end;
    function GetHZCode(vHZ: string): string;
    //vHZ:一个汉字
    //返回区位码字符串,GB2312中没有的字返回0000
    var
    QM, WM: Integer;
    tStr: string;
    begin
    tStr := ;
    QM := Ord(vHZ[1])-160;
    WM := Ord(vHZ[2])-160;
    if (QM<0) or (WM<0) then
    begin
    QM := 0;
    WM := 0;
    end;if QM <10 then
    tStr := 0+IntToStr(QM)
    else
    tStr := IntToStr(QM);
    if WM < 10 then
    tStr := tStr+0+IntToStr(WM)
    else
    tStr := tStr+IntToStr(WM);GetHZCode := tStr;
    end;
      

  2.   

    这里有C#写的,如何把里面的方法转成java的方法呢:
    public string CodingToCharacter(string coding) 

    string characters = ""; 
    if (coding.Length % 4 != 0)//编码为16进制,必须为4的倍数。 

    throw new System.Exception("编码格式不正确"); 

    for (int i = 0; i<coding.Length; i+=4 ) //每四位为一个汉字 

    byte[] bytes = new byte[2]; 
    string lowCode = coding.Substring(i, 2); //取出低字节,并以16进制进制转换 
    bytes[0] = System.Convert.ToByte(lowCode, 16); 
    string highCode = coding.Substring(i + 2, 2); //取出高字节,并以16进制进行转换 
    bytes[1] = System.Convert.ToByte(highCode, 16); 
    string character = System.Text.Encoding.Unicode.GetString(bytes); 
    characters += character; 

    return characters; 

      

  3.   

    已经解决了,供大家参考一下:public String CodeToChinese (String code) {    String Chinese = "";    for (int i = 0; i < code.length(); i +=4) {
                    byte[] bytes = new byte[2];
                    String lowCode = code.substring(i, i+2);
                    int tempLow = Integer.parseInt(lowCode, 16);
                    tempLow += 160;              
                    bytes[0] = (byte) tempLow;
                      
                    String highCode = code.substring(i+2, i+4);              
                    int tempHigh = Integer.parseInt(highCode, 16);
                    tempHigh += 160;             
                    bytes[1] = (byte) tempHigh;
                    
                    String chara = new String(bytes);
                    Chinese += chara;
                }
        return Chinese;}
      

  4.   

    to: liuzichang(刘子)
    为什么tempLow 和tempHigh要加上160?