得到汉字的拼音

来源:互联网 发布:淘宝关键词提取 编辑:程序博客网 时间:2024/04/20 02:22
function TForm1.getpy(sHZ: string): string;
var
  i: Integer;
  PY: string;
  s: string;
  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(32);
    end;
  end;
begin
  s := '';
  i := 1;
  while i <= Length(sHZ) do
  begin
    PY := Copy(sHZ, i, 1);
    if PY >= Chr(128) then
    begin
      Inc(i);
      PY := PY + Copy(sHZ, i, 1);
      s := s + GetPYIndexChar(PY);
    end
    else
      s := s + PY;
    Inc(i);
  end;
  result := s;
end;