您的位置:首页 > 编程语言 > Delphi

(Delphi函数)根据汉字,得到拼音的缩写

2004-09-02 15:37 411 查看
function GetPinYin(sHZ: string;mode: integer = 1): 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;
case mode of
1: result := UpperCase(s);
2: result := LowerCase(s);
else
result := s;
end; //case
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: