看了这个函数就明白了吧?
function TForm1.GetPYIndexChar(hzchar: string): char;
begin
  case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
    $B0A1..$B0C4 : result := 'A';
    $B0C5..$B2C0 : result := 'B';
    $B2C1..$B4ED : result := 'C';
    $B4EE..$B6E9 : result := 'D';
    $B6EA..$B7A1 : result := 'E';
    $B7A2..$B8C0 : result := 'F';
    $B8C1..$B9FD : result := 'G';
    $B9FE..$BBF6 : result := 'H';
    $BBF7..$BFA5 : result := 'J';
    $BFA6..$C0AB : result := 'K';
    $C0AC..$C2E7 : result := 'L';
    $C2E8..$C4C2 : result := 'M';
    $C4C3..$C5B5 : result := 'N';
    $C5B6..$C5BD : result := 'O';
    $C5BE..$C6D9 : result := 'P';
    $C6DA..$C8BA : result := 'Q';
    $C8BB..$C8F5 : result := 'R';
    $C8F6..$CBF9 : result := 'S';
    $CBFA..$CDD9 : result := 'T';
    $CDDA..$CEF3 : result := 'W';
    $CEF4..$D188 : result := 'X';
    $D1B9..$D4D0 : result := 'Y';
    $D4D1..$D7F9 : result := 'Z';
  else
    result := char(0);
  end;
end;

解决方案 »

  1.   

    上面的方法你查个‘血’字试一下:
    应该为:
        $CEF4..$D1B8 : Result := 'X';
        $D1B9..$D4D0 : Result := 'Y';
    但这个方法好象还是有不少汉字找不到的,
    如‘枇杷’
      

  2.   

    function TOWSelectBox.GetSpellChar(Chinese: String): Char;
    begin
      if Chinese='' then
         Result := chr(0)
      else
      case WORD(Chinese[1]) shl 8 + WORD(Chinese[2]) of
        $B0A1..$B0C4 : Result := 'A';
        $B0C5..$B2C0 : Result := 'B';
        $B2C1..$B4ED : Result := 'C';
        $B4EE..$B6E9 : Result := 'D';
        $B6EA..$B7A1 : Result := 'E';
        $B7A2..$B8C0 : Result := 'F';
        $B8C1..$B9FD : Result := 'G';
        $B9FE..$BBF6 : Result := 'H';
        $BBF7..$BFA5 : Result := 'J';
        $BFA6..$C0AB : Result := 'K';
        $C0AC..$C2E7 : Result := 'L';
        $C2E8..$C4C2 : Result := 'M';
        $C4C3..$C5B5 : Result := 'N';
        $C5B6..$C5BD : Result := 'O';
        $C5BE..$C6D9 : Result := 'P';
        $C6DA..$C8BA : Result := 'Q';
        $C8BB..$C8F5 : Result := 'R';
        $C8F6..$CBF9 : Result := 'S';
        $CBFA..$CDD9 : Result := 'T';
        $CDDA..$CEF3 : Result := 'W';
        $CEF4..$D1B8 : Result := 'X';
        $D1B9..$D4D0 : Result := 'Y';
        $D4D1..$D7F9 : Result := 'Z';
      else
        Result := Chinese[1];
      end;
    end;function TOWSelectBox.HowManyChineseChar(const s: String): Integer;
    var
      sw: WideString;
      c: String;
      i,wCount: Integer;
    begin
      Result := 0;
      if Trim(s)='' then
         Exit;
      sw := s;
      wCount := 0;
      for i:=0 to Length(sw) do
      begin
        c := sw[i];
        if Length(c)>1 then
           Inc(wCount);
      end;
      Result := wCount;
    end;function  TOWSelectBox.ChinesetoEnglish(str: String): String;
    var
      i,count: Integer;
      strTemp: String;
    begin
      Result := '';
      count := HowManyChineseChar(str);
      if count=0 then
         Result := str;
      for i:=0 to Length(str) div 2 - 1 do
      begin
        strTemp := Copy(str,(i+1)*2-1,2);
        Result := Result + GetSpellChar(strTemp);
      end;
      Result := UpperCase(Result);
    end;
      

  3.   

    这办法没有实际意义,道理很简单,gb2312只有第一区是按照拼音排的。你可以利用win98里面的输入法生成器,导出拼音输入法成文本文件,稍作整理,去掉词。
    就得到了汉字和拼音的对应表。
    写个程序自己查就行了。
      

  4.   

    //我和上面的都是一个道理
    //这是我自己编的取区位码const
      cMinGBCByte = 161;                           //最小国标字节function StrToGBC(mStr: string): string;
    begin
      if Length(mStr) = 2 then
        if [mStr[1], mStr[2]] <= cGBCCharSet then
          Result := FormatFloat('0#', Ord(mStr[1]) - cMinGBCByte + 1)
            + FormatFloat('0#', Ord(mStr[2]) - cMinGBCByte + 1)
        else Result := '0000'
      else Result := '9999';
    end; { StrToGBC }function GBCToStr(mStr: string): string;
    var
      I, J: Integer;
    begin
      I := StrToIntDef(mStr, 0);
      J := I mod 100;
      I := I div 100;
      I := I + cMinGBCByte - 1;
      J := J + cMinGBCByte - 1;
      if [I, J] <= cGBCByteSet then
        Result := Chr(I) + Chr(J)
      else Result := '';
    end; { GBCToStr }function WordStrCnToShort(mStr: string): string;
    var
      I: Integer;
    begin
      I := StrToIntDef(StrToGBC(mStr), 0);
      case I of
        1601..1636: Result := 'A';
        1637..1832: Result := 'B';
        1833..2078: Result := 'C';
        2079..2273: Result := 'D';
        2274..2301: Result := 'E';
        2302..2432: Result := 'F';
        2433..2593: Result := 'G';
        2594..2786,8032: Result := 'H';
    //            ~~~~~没有的看它的区位码就加
        2787..3105: Result := 'J';
        3106..3211: Result := 'K';
        3212..3471: Result := 'L';
        3472..3634: Result := 'M';
        3635..3721: Result := 'N';
        3722..3729: Result := 'O';
        3730..3857: Result := 'P';
        3858..4026: Result := 'Q';
        4027..4085: Result := 'R';
        4086..4389: Result := 'S';
        4390..4557: Result := 'T';
        4558..4683: Result := 'W';
        4694..4924: Result := 'X';
        4925..5248: Result := 'Y';
        5249..5589: Result := 'Z';
      else Result := '_';
      end;
    end; { WordStrCnToShort }function StrToShort(mStr: string; mCount: Integer = -1): string;
    var
      I, K: Integer;
    begin
      Result := '';
      K := 0;
      for I := 1 to Length(mStr) do begin
        if K = mCount then Break;
        case ByteType(mStr, I) of
          mbSingleByte: begin
            Result := Result + mStr[I];
            Inc(K);
          end;
          mbTrailByte: begin
            Result := Result + WordStrCnToShort(Copy(mStr, I - 1, 2));
            Inc(K);
          end;
        end;
      end;
    end; { StrToShort }
      

  5.   

    const
    const
      cMinGBCByte = 161;                           //最小国标字节
      cMaxGBCByte = 254;                           //最大国标字节
      cGBCByteSet = [cMinGBCByte..cMaxGBCByte];    //国标字节集合
      cMinGBCChar = Chr(cMinGBCByte);              //最小国标字符
      cMaxGBCChar = Chr(cMaxGBCByte);              //最大国标字符
      cGBCCharSet = [cMinGBCChar..cMaxGBCChar];    //国标字符集合