Delphi XE 擷取漢字拼音首字母

來源:互聯網
上載者:User
unction  CnPYIndex( const  CnString: string): string;
{
  返回中文的拼音首字母
}
const
  ChinaCode:  array [ 0 .. 25 ,  0 .. 1 ]  of  Integer  =  (( 1601 ,  1636 ), ( 1637 ,  1832 ), ( 1833 ,  2077 ),
    ( 2078 ,  2273 ), ( 2274 ,  2301 ), ( 2302 ,  2432 ), ( 2433 ,  2593 ), ( 2594 ,  2786 ), ( 9999 ,  0000 ),
    ( 2787 ,  3105 ), ( 3106 ,  3211 ), ( 3212 ,  3471 ), ( 3472 ,  3634 ), ( 3635 ,  3722 ), ( 3723 ,  3729 ),
    ( 3730 ,  3857 ), ( 3858 ,  4026 ), ( 4027 ,  4085 ), ( 4086 ,  4389 ), ( 4390 ,  4557 ), ( 9999 ,  0000 ),
    ( 9999 ,  0000 ), ( 4558 ,  4683 ), ( 4684 ,  4924 ), ( 4925 ,  5248 ), ( 5249 ,  5589 ));
var
  i, j, HzOrd, l_iHz: Integer;
  Hz: AnsiString;
begin
  i : =    1 ;
  l_iHz : = 1 ;
   while  i  <=  Length(CnString)  do
   begin
    Hz : =  CnString[i];
     if  (Hz[l_iHz]  >=  # 160 )  and  (Hz[l_iHz  + 1 ]  >=  # 160 )  then
     begin
      HzOrd : =  (Ord(Hz[l_iHz])  - 160 )  * 100 +  Ord(Hz[l_iHz  + 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(

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.