取得汉字的拼音首字母

function  GetChineseAsc(const crStr:String;crLength:Integer):String;
var i,HighPosition,LowPosition:Integer;
    AscValue,AscStr:String;
begin
  Result:='';
  i:=2; //1个汉字占用两个字节
  while i<=Length(crStr) do
  begin
    if Length(Trim(Result))=crLength then Break; //如果超过一定长度,则退出
    HighPosition:=Ord(crStr[i-1])-160;
    LowPosition:=Ord(crStr[i])-160;
    if (HighPosition<16) or (HighPosition>55) or (LowPosition<=0) or (LowPosition>94) then
    begin
      //if HighPosition>
      if crStr[i-1] in ['a'..'z','A'..'Z'] then
        Result:=Result+UpperCase(crStr[i-1]);
      i:=i+1;
      Continue;
    end;
    AscValue:=FormatFloat('00',HighPosition)+FormatFloat('00',LowPosition);
    AscStr:='';
    if (AscValue>='1601') and (AscValue<='1636') then
      AscStr:='A';
    if (AscValue>='1637') and (AscValue<='1832') then
      AscStr:='B';
    if (AscValue>='1833') and (AscValue<='2077') then
      AscStr:='C';
    if (AscValue>='2078') and (AscValue<='2273') then
      AscStr:='D';
    if (AscValue>='2274') and (AscValue<='2301') then
      AscStr:='E';
    if (AscValue>='2302') and (AscValue<='2432') then
      AscStr:='F';
    if (AscValue>='2433') and (AscValue<='2593') then
      AscStr:='G';
    if (AscValue>='2594') and (AscValue<='2786') then
      AscStr:='H';
    if (AscValue>='2787') and (AscValue<='3105') then
      AscStr:='J';
    if (AscValue>='3106') and (AscValue<='3211') then
      AscStr:='K';
    if (AscValue>='3212') and (AscValue<='3471') then
      AscStr:='L';
    if (AscValue>='3472') and (AscValue<='3634') then
      AscStr:='M';
    if (AscValue>='3635') and (AscValue<='3721') then
      AscStr:='N';
    if (AscValue>='3722') and (AscValue<='3729') then
      AscStr:='O';
    if (AscValue>='3730') and (AscValue<='3857') then
      AscStr:='P';
    if (AscValue>='3858') and (AscValue<='4026') then
      AscStr:='Q';
    if (AscValue>='4027') and (AscValue<='4085') then
      AscStr:='R';
    if (AscValue>='4086') and (AscValue<='4389') then
      AscStr:='S';
    if (AscValue>='4390') and (AscValue<='4557') then
      AscStr:='T';
    if (AscValue>='4558') and (AscValue<='4683') then
      AscStr:='W';
    if (AscValue>='4684') and (AscValue<='4924') then
      AscStr:='X';
    if (AscValue>='4925') and (AscValue<='5248') then
      AscStr:='Y';
    if (AscValue>='5249') and (AscValue<='5589') then
      AscStr:='Z';
    Result:=Result+AscStr;
    I:=I+2
  end;
end; 
阅读更多
换一批

没有更多推荐了,返回首页