现在的位置: 首页 > 综合 > 正文

Delphi中取得汉字的首字母

2012年10月19日 ⁄ 综合 ⁄ 共 1107字 ⁄ 字号 评论关闭
function Tdm.GetHzPy(const AHzStr: string): string;
const
  ChinaCode: array[
0..250..1] of Integer = ((16011636), (16371832), (18332077),
  (
20782273), (22742301), (23022432), (24332593), (25942786), (99990000),
  (
27873105), (31063211), (32123471), (34723634), (36353722), (37233729),
  (
37303857), (38584026), (40274085), (40864389), (43904557), (99990000),
  (
99990000), (45584683), (46844924), (49255248), (52495589));
var
    i, j, HzOrd: integer;
//    Hz: string[2];
begin
    i :
= 1;
    
while i <= Length(AHzStr) do
    begin
        
if (AHzStr[i] >= #160) and (AHzStr[i + 1>= #160) then
        begin
            HzOrd :
= (Ord(AHzStr[i]) - 160* 100 + Ord(AHzStr[i + 1]) - 160;
            
for j := 0 to 25 do
            begin
                
if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then
                begin
                    Result :
= Result + char(byte('A'+ j);
                    
break;
                end;
            end;
            Inc(i);
        end 
else Result := Result + AHzStr[i];
        Inc(i);
    end;
end;

很久前的代码,忘记了来源,很好用

抱歉!评论已关闭.