可以使用汉字的内码或者区位码,汉字在一个区间内的拼音首字母是一个字母(A,B,C)

解决方案 »

  1.   

    不知道你要计算什么, 如果是排序的话, 可以按拼音排(用ACCESS很方便)
      

  2.   

    在数据库输入中,怎样使"中文名称"输入翻译成"简码"存入另一字段?以便以后查询使用?
    如:
      "工资处"译成"GZC"  
    //这个函数拿去用(我刚写好,已测试通过)
    function GetHzPy(const AHzStr: string): string;
    const
      ChinaCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077),
        (2078, 2273), (2274, 2301), (2302, 2432), (2433, 2593), (2594, 2786), (9999, 0000),
        (2787, 3105), (3106, 3211), (3212, 3471), (3472, 3634), (3635, 3722), (3723, 3729),
        (3730, 3857), (3858, 4026), (4027, 4085), (4086, 4389), (4390, 4557), (9999, 0000),
        (9999, 0000), (4558, 4683), (4684, 4924), (4925, 5248), (5249, 5589));
    var
      i, j, HzOrd: integer;
      Hz: string[2];
    begin
      i := 1;
      while i <= Length(AHzStr) do
      begin
        if (AHzStr[i] >= #160) and (AHzStr[i + 1] >= #160) then
        begin
          HzOrd := (Ord(AHzStr[i]) - 160) * 100 + Ord(AHzStr[i + 1]) - 160;
          for j := 0 to 25 do
          begin
            if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then
            begin
              Result := Result + char(byte('A') + j);
              break;
            end;
          end;
          Inc(i);
        end else Result := Result + AHzStr[i];
        Inc(i);
      end;
    end;///////////////////////////////////////
    这个函数用户识别单独汉字的简码 字符串的简码函数请自行制作
    function GetPYIndexChar(hzchar:string):char;
      

  3.   

    分段查找法的确实现起来很容易 可是 他是根据汉字的区位码进行排序的 我们都知道 它是分级的,lx_king(天剑) 好像只实现了一级码 ,不知道那里能找到2,3 级的编码规则
      

  4.   

    一级字库是按拼音顺序排列的,可以用lx_king(天剑)的方法查,
    二级字库是按笔划排列的,用上面方法就不行了
    而且汉字里有很多多音字,所以取出来的字母也不一定就是你想要的
    用Api好象可以查出来,而且不仅是查拼音,查其它输入法也可以,我帮你查一下
      

  5.   

    function 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;
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        ListBox1: TListBox;
        ListBox2: TListBox;
        Label2: TLabel;
        Label1: TLabel;
        procedure Edit1Change(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationfunction GetCharInd(zzchar:string):char;
    begin
      case WORD(zzchar[1]) shl 8+WORD(zzchar[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:=#0;
      end;
    end;function DisByStrInd(ListBoxStr:TListBox;StrInd:string):string;
    label NotFound;
    var
      zzchar :string;
      i,j:integer;
    begin
      for i:=0 to ListBoxStr.Items.Count-1 do
      begin
        for j:=1 to Length(StrInd) do
        begin
          zzchar:=ListBoxStr.Items[i][2*j-1]+ListBoxStr.Items[i][2*j];
          if (StrInd[j]<>'?') and (UpperCase(StrInd[j])<>GetCharInd(zzchar))
          then goto NotFound;
        end;
        if result='' then result:=ListBoxStr.Items[i]
        else result:=result+#13+ListBoxStr.Items[i];
    NotFound:
      end;
    end;{$R *.DFM}procedure TForm1.Edit1Change(Sender: TObject);
    var
      SelStr:string;
    begin
      SelStr:='';
      ListBox2.Items.Text:=DisByStrInd(listBox1,Edit1.Text);
    end;end.