Delphi 汉字转拼音,技持多个汉字一起转

unit Unit1;



interface



uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.StdCtrls;



type

  TForm1 = class(TForm)

    SpeedButton1: TSpeedButton;

    Edit1: TEdit;

    Edit2: TEdit;

    procedure SpeedButton1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}

Function GetPinyin_shoupinma2(hz: String): ansiChar;//获取生僻字首拼码

begin

  case hz[1] of

    '': Result := 'A';

    '': Result := 'A';

    '': Result := 'A';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'C';

    '': Result := 'C';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'D';

    '': Result := 'E';

    '': Result := 'F';

    '': Result := 'F';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'G';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'H';

    '': Result := 'J';

    '槿': Result := 'J';

    '': Result := 'J';

    '': Result := 'J';

    '': Result := 'K';

    '': Result := 'K';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'L';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'M';

    '': Result := 'N';

    '': Result := 'N';

    '': Result := 'N';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'P';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'Q';

    '': Result := 'R';

    '': Result := 'S';

    '': Result := 'S';

    //'': Result := 'S';

    '': Result := 'S';

    '': Result := 'S';

    '': Result := 'T';

    '': Result := 'T';

    '': Result := 'W';

    '': Result := 'X';

    //'': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'X';

    '': Result := 'Y';

    '': Result := 'Y';

    '': Result := 'Y';

    '': Result := 'Y';

    '': Result := 'Y';

    '': Result := 'Y';

    '': Result := 'Z';

    //'': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';

    //'': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'D';

    '': Result := 'Z';

    '': Result := 'B';

    '': Result := 'B';

    '': Result := 'E';

    '': Result := 'F';

    '': Result := 'J';

    '': Result := 'J';

    '': Result := 'P';

    '': Result := 'S';

    '': Result := 'T';

    '': Result := 'Y';

    '': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';

    '': Result := 'Z';





    '', '', '', '', '', '', '', '', '', '', '', '', {'桉',}

    '', '', '', '', {'铵',} '', '', '', '', '', '', '', '',

    ''{, '螯'}, '', '', '', '', '', ''{, '廒'}:

    Result := 'a';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', ''{, '孢'}, '', '', ''{, '葆'}, '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '吡'}, '', '', '', '', '', '', '', ''{,

    '铋'}, '', ''{, '萆'}, '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '苄'}, '', '', '', '', '', '', '', '',

    '', '', '', '', '', ''{, '缤'}, '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '檗'}, '', '', '', '', '', '', '', '', '', '':

    Result := 'b';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', ''{, '豉'}, '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '苁'}, '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '':

    Result := 'c';



    '', '', '', '', '', '', '', '', '', ''{, '甙'}, '', '',

    '', ''{, '黛'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '菪'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '癜'}, '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', ''{, '酊'}{, '啶'}, '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', ''{, '窦'},

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', ''{,

    '哚'}, '', '', '', '', '', '', '', '', '', '':

    Result := 'd';



    ''{, '莪'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '':

    Result := 'e';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', ''{, '呋'}, '', '', '', '', '', ''{, '芙'}, '', '',

    '', '', '', '', ''{{, '茯'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '':

    Result := 'f';



    '', '', '', '', '', '', '', '', '', '', '', '', ''{,

    '苷'}, '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '膈'}, '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '枸'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', ''{, '钴'}, '', '', '', '',

    '', '', '', '', ''{, '胍'}, ''{, '呱'}, '', '', '', '', '',

    '', '', '', '', ''{, '胱'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '':

    Result := 'g';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '诃'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '斛'}, '',

    '', '', '', '', '', ''{, '琥'}, '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '癀'}, '', '', '', '', '', '', '', '', '', ''{,

    '茴'}, '', ''{, '荟'}, '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', ''{, '藿'}, '', '', '',

    '':

    Result := 'h';



    #0: Result := 'i';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', ''{,

    '蚧'}, '', '', '', '', '', '', '', ''{, '槿'}, '', '', '',

    '', '', '', '', '', '', '', '', '', ''{, '肼'}, '', '',

    '', '', ''{, '婧'}, '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '':

    Result := 'j';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '喹'}, '',

    '', '', '', '', ''{, '匮'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '':

    Result := 'k';



    ''{, '靓'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '莨'}, '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '缧'}, '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', ''{, '蛎'}, '', '',

    '', '', '', '', '', '', '', ''{, '蠊'}, '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', ''{,

    '蓼'}, '', '', '', '', '', '', '', '', ''{, '啉'}, '', '',

    '', '', '', '', '', '', '', ''{, '膦'}, '', '', ''{, '苓'},

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', ''{,

    '癃'}, '', ''{, '偻'}, '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '':

    Result := 'l';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '蟆'}, '',

    '', '', '', '', '', '', ''{, '鳗'}, '', '', '', '', '',

    '', '', '', '', '', '', '', '', ''{, '蝥'}, '', '', '',

    '', '', '', '', '', '', ''{, '莓'}, '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', ''{, '咪'}, '', '', '', '', '', '',

    '', '', '', '', '', '', ''{, '嘧'}, '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '茉'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '':

    Result := 'm';



    '', '', '', '', '', '', '', '', ''{, '萘'}, '', ''{, '喃'},

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '廿', '', '', '', ''{, '脲'}, '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '':

    Result := 'n';



    '', '', '', '', '':

    Result := 'o';



    '', '', '', '', ''{, '杷'}, '', ''{, '哌'}, '', '', '', ''{,

    '泮'}, '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '枇'}, '', '', '', '', '', '', '', '', '', '',

    '', ''{, '癖'}, '', '', '', '', '', '', '', '', '', '',

    '', ''{, '螵'}, '', ''{, '嘌'}, '', '', '丿', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', ''{, '珀'},

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '':

    Result := 'p';



    '', '', '', '', ''{, '瞿'}, '', '', '', '', '', '', '',

    ''{, '芪'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '杞'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '羟'}, '', '', '', '', '', ''{, '荞'},

    '', '', '', '', '', '', '', '', '', '', '', ''{, '芩'}{,

    '嗪'}, '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', ''{, '巯'}, '', '', '', '', '',

    '', ''{, '祛'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', ''{, '镪'}:

    Result := 'q';



    ''{, '髯'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '':

    Result := 'r';



    '', '', '', '', '', '', '', '', ''{, '噻'}, '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', ''{, '痧'},

    ''{, '鲨'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', ''{, '麝'}, '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', ''{, '挲'}{, '挲'}, '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '':

    Result := 's';



    '', '', '', '', '', '', '', '趿', '', '', '', '', '',

    '', '', '', '', '', '', ''{, '肽'}, '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '氽'}, ''{,

    '佗'}, '', '', '', '', '', '', '', '', '', '', '':

    Result := 't';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '诿', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '肟'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '':

    Result := 'w';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '酰'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '逍'}, '', '', '', '', '', '', '',

    ''{, '缬'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', ''{, '馨'}{, '鑫'}, '', '', '', '', '', ''{, '芎'},

    '', '', '', '', '', '', ''{, '溴'}, '', '', '', '', '',

    ''{, '醑'}, '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', ''{, '鳕'},

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '':

    Result := 'x';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '妍'}, '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '怡'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '驿', '', '', '羿', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '翳'}, '', '', '', '', '', '', '',

    '', '', '', '', ''{, '龈'}, ''{, '吲'}, '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '鱿', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '橼'}, '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '':

    Result := 'y';



    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', ''{, '觜'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '喋'}, '',

    '', ''{, '甾'}, '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', ''{, '楂'}, '', '', '', '', '', '', '',

    '', '', '', '', '', '', ''{, '蟑'}, '', '', '', '', '',

    '', '', '', '', '', '', '', ''{, '赭'}, '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', ''{, '栀'}, '', '', '', ''{,

    '跖'}, '', '', '', '', '', '', '', ''{, '酯'}, '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '', ''{, '竺'}, '', '',

    '', '', '', '', '', '', '', '', '', '', '', '', '',

    '', '', '', '', '', '', '', '', '涿', '', '', '', '',

    '', '', '', '', '', '', '', '', '', '', ''{, '唑'}:

    Result := 'z';

  end;

end;



Function Getpinyin_shoupinma(hzchar: Ansistring): ansichar; //获得常用字首拼码

var

  i: Integer;

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 := GetPinyin_shoupinma2(hzchar);

  end;

end;

Function HZToPY(cSTR:String):String;

 Var

   i:integer;

   S:String;

  begin

   Result:='';

    for I := 1 to Length(cSTR) do

       begin

          S:=Copy(cSTR,i,1);

         if Trim(Getpinyin_shoupinma(S))='' then

            Result:=Result+S

            else

          Result:=Result+Getpinyin_shoupinma(S);

       end;

  end;



procedure TForm1.SpeedButton1Click(Sender: TObject);

begin

 Edit2.Text:=HZToPY(Edit1.Text);

end;



end.



如:"你是" 转为NS



     "你a1是" 转为Na1S

 

你可能感兴趣的:(Delphi)