Tag: 汉字预览模式: 普通 | 列表

汉字翻译成拼音简写

Delphi代码
  1. 在数据库输入中,怎样使"中文名称"输入翻译成"简码"存入另一字段?以便以后查询使用?  
  2. 如: "工资处"译成"GZC"  
  3.   
  4. //这个函数拿去用(我刚写好,已测试通过)  
  5. function GetHzPy(const AHzStr: string): string;  
  6. const  
  7.   ChinaCode: array[0..250..1of Integer = ((16011636), (16371832), (18332077),  
  8.     (20782273), (22742301), (23022432), (24332593), (25942786), (99990000),  
  9.     (27873105), (31063211), (32123471), (34723634), (36353722), (37233729),  
  10.     (37303857), (38584026), (40274085), (40864389), (43904557), (99990000),  
  11.     (99990000), (45584683), (46844924), (49255248), (52495589));  
  12. var  
  13.   i, j, HzOrd: integer;  
  14.   Hz: string[2];  
  15. begin  
  16.   i := 1;  
  17.   while i <= Length(AHzStr) do  
  18.   begin  
  19.     if (AHzStr[i] >= #160and (AHzStr[i + 1] >= #160then  
  20.     begin  
  21.       HzOrd := (Ord(AHzStr[i]) - 160) * 100 + Ord(AHzStr[i + 1]) - 160;  
  22.       for j := 0 to 25 do  
  23.       begin  
  24.         if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then  
  25.         begin  
  26.           Result := Result + char(byte('A') + j);  
  27.           break;  
  28.         end;  
  29.       end;  
  30.       Inc(i);  
  31.     end else Result := Result + AHzStr[i];  
  32.     Inc(i);  
  33.   end;  
  34. end;  
  35.   
  36. ///////////////////////////////////////  
  37. 这个函数用户识别单独汉字的简码 字符串的简码函数请自行制作  
  38. function GetPYIndexChar(hzchar:string):char;  
  39. begin  
  40.   case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of  
  41.     $B0A1..$B0C4 : result := 'A';  
  42.     $B0C5..$B2C0 : result := 'B';  
  43.     $B2C1..$B4ED : result := 'C';  
  44.     $B4EE..$B6E9 : result := 'D';  
  45.     $B6EA..$B7A1 : result := 'E';  
  46.     $B7A2..$B8C0 : result := 'F';  
  47.     $B8C1..$B9FD : result := 'G';  
  48.     $B9FE..$BBF6 : result := 'H';  
  49.     $BBF7..$BFA5 : result := 'J';  
  50.     $BFA6..$C0AB : result := 'K';  
  51.     $C0AC..$C2E7 : result := 'L';  
  52.     $C2E8..$C4C2 : result := 'M';  
  53.     $C4C3..$C5B5 : result := 'N';  
  54.     $C5B6..$C5BD : result := 'O';  
  55.     $C5BE..$C6D9 : result := 'P';  
  56.     $C6DA..$C8BA : result := 'Q';  
  57.     $C8BB..$C8F5 : result := 'R';  
  58.     $C8F6..$CBF9 : result := 'S';  
  59.     $CBFA..$CDD9 : result := 'T';  
  60.     $CDDA..$CEF3 : result := 'W';  
  61.     $CEF4..$D188 : result := 'X';  
  62.     $D1B9..$D4D0 : result := 'Y';  
  63.     $D4D1..$D7F9 : result := 'Z';  
  64.   else  
  65.     result := char(0);  
  66.   end;  
  67. end;  

Tags: 汉字 翻译 拼音 简写

分类:Delphi | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 39