取汉字首字母的问题,有些字取不到,苦脑死了 ( 积分: 100 )

  • 主题发起人 主题发起人 wqhatnet
  • 开始时间 开始时间
W

wqhatnet

Unregistered / Unconfirmed
GUEST, unregistred user!
乐乐
这两个汉字为什么会取不到呢?

function GetPinYinFirstLetter(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 := 'K';
$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 := ' ';
// Result := Char(0);
end;
end;
 
//测试下面的看看
function CharToShort( // 得到汉字的拼音简码
AChar: WideChar // 单个汉字
): Char; // 返回单个汉字的拼音简码
begin
if (AChar >= '啊') and (AChar <= '澳') then
Result := 'A'
else if (AChar >= '芭') and (AChar <= '怖') then
Result := 'B'
else if (AChar >= '擦') and (AChar <= '搭') then
Result := 'C'
else if (AChar >= '达') and (AChar <= '堕') then
Result := 'D'
else if (AChar >= '蛾') and (AChar <= '贰') then
Result := 'E'
else if (AChar >= '发') and (AChar <= '咐') then
Result := 'F'
else if (AChar >= '噶') and (AChar <= '过') then
Result := 'G'
else if (AChar >= '哈') and (AChar <= '祸') then
Result := 'H'
else if (AChar >= '击') and (AChar <= '骏') then
Result := 'J'
else if (AChar >= '喀') and (AChar <= '阔') then
Result := 'K'
else if (AChar >= '垃') and (AChar <= '络') then
Result := 'L'
else if (AChar >= '妈') and (AChar <= '穆') then
Result := 'M'
else if (AChar >= '拿') and (AChar <= '诺') then
Result := 'N'
else if (AChar >= '哦') and (AChar <= '沤') then
Result := 'O'
else if (AChar >= '啪') and (AChar <= '瀑') then
Result := 'P'
else if (AChar >= '期') and (AChar <= '群') then
Result := 'Q'
else if (AChar >= '然') and (AChar <= '弱') then
Result := 'R'
else if (AChar >= '撒') and (AChar <= '所') then
Result := 'S'
else if (AChar >= '塌') and (AChar <= '唾') then
Result := 'T'
else if (AChar >= '挖') and (AChar <= '误') then
Result := 'W'
else if (AChar >= '牺') and (AChar <= '迅') then
Result := 'X'
else if (AChar >= '压') and (AChar <= '孕') then
Result := 'Y'
else if (AChar >= '匝') and (AChar <= '座') then
Result := 'Y'
else Result := '_';
end; { CharToShort }

function StringToShort( // 得到字符串的拼音简码
AString: WideString // 字符串
): string; // 返回拼音简码,如果是字母则不改变
var
I: Integer;
begin
Result := '';
for I := 1 to Length(AString) do
if AString > #255 then
Result := Result + CharToShort(AString)
else Result := Result + UpperCase(AString);
end; { StringToShort }
 
这个不全的,少了2级字库的处理,全的论坛有的,自己搜吧!
 
上面两个程序都是不全的,比如某些字,如 嵩,蟑螂 等就查不出来
,去看看
http://www.2ccc.com/article.asp?articleid=12
 
后退
顶部