Delphi 获取单汉字拼音首字母


本文整理自网络,侵删。

 
uses StrUtils;

function GetCharSpellCode(cnStr: string): string;
var
  buf: TBytes;
  i: Integer;
  icnStrCount: Int64;
  i1, i2: Integer;
  tmpStr: string[4];
begin
  Result := '';
  // TODO -cMM: TForm1.GetCharSpellCode default body inserted
  SetLength(buf, 4);
  //
  tmpStr := cnStr;
  for i := 0 to 3 do
    buf[i] := Byte(tmpStr[i]);

  i1 := int16(buf[1]);
  i2 := int16(buf[2]);
  icnStrCount := i1 * 256 + i2;
  if (icnStrCount >= 45217) and (icnStrCount <= 45252) then
  begin
    Result := 'A';
    Exit;
  end;
  if (icnStrCount >= 45253) and (icnStrCount <= 45760) then
  begin
    Result := 'B';
    Exit;
  end;

  if (icnStrCount >= 45761) and (icnStrCount <= 46317) then
  begin
    Result := 'C';
    Exit;
  end;

  if (icnStrCount >= 46318) and (icnStrCount <= 46825) then
  begin
    Result := 'D';
    Exit;
  end;

  if (icnStrCount >= 46826) and (icnStrCount <= 47009) then
  begin
    Result := 'E';
    Exit;
  end;

  if (icnStrCount >= 47010) and (icnStrCount <= 47296) then
  begin
    Result := 'F';
    Exit;
  end;

  if (icnStrCount >= 47297) and (icnStrCount <= 47613) then
  begin
    Result := 'G';
    Exit;
  end;

  if (icnStrCount >= 47614) and (icnStrCount <= 48118) then
  begin
    Result := 'H';
    Exit;
  end;

  if (icnStrCount >= 48119) and (icnStrCount <= 49061) then
  begin
    Result := 'J';
    Exit;
  end;

  if (icnStrCount >= 49062) and (icnStrCount <= 49323) then
  begin
    Result := 'K';
    Exit;
  end;

  if (icnStrCount >= 49324) and (icnStrCount <= 49895) then
  begin
    Result := 'L';
    Exit;
  end;
  if (icnStrCount >= 49896) and (icnStrCount <= 50370) then
  begin
    Result := 'M';
    Exit;
  end;
  if (icnStrCount >= 50371) and (icnStrCount <= 50613) then
  begin
    Result := 'N';
    Exit;
  end;
  if (icnStrCount >= 50614) and (icnStrCount <= 50621) then
  begin
    Result := 'O';
    Exit;
  end;
  if (icnStrCount >= 50622) and (icnStrCount <= 50905) then
  begin
    Result := 'P';
    Exit;
  end;
  if (icnStrCount >= 50906) and (icnStrCount <= 51386) then
  begin
    Result := 'Q';
    Exit;
  end;
  if (icnStrCount >= 51387) and (icnStrCount <= 51445) then
  begin
    Result := 'R';
    Exit;
  end;
  if (icnStrCount >= 51446) and (icnStrCount <= 52217) then
  begin
    Result := 'S';
    Exit;
  end;
  if (icnStrCount >= 52218) and (icnStrCount <= 52697) then
  begin
    Result := 'T';
    Exit;
  end;
  if (icnStrCount >= 52698) and (icnStrCount <= 52979) then
  begin
    Result := 'W';
    Exit;
  end;
  if (icnStrCount >= 52980) and (icnStrCount <= 53688) then
  begin
    Result := 'X';
    Exit;
  end;
  if (icnStrCount >= 53689) and (icnStrCount <= 54480) then
  begin
    Result := 'Y';
    Exit;
  end;
  if (icnStrCount >= 54481) and (icnStrCount <= 55289) then
  begin
    Result := 'Z';
    Exit;
  end;
  Result := UpperCase(cnStr);
end;

相关阅读 >>

Delphi 绘制精美的签名图片

Delphi opendialog1文件过滤类型

Delphi 中showmodal与show的区别

Delphi 获取计算机已运行时间

Delphi base64, quoted-printable 的解码与编码函数

Delphi xe 提权代码

Delphi中bitmap位图与base64字符串相互转换

Delphi 改造shellexecute 精简函数

Delphi提取exe,dll文件的icon图标

Delphi xe5 android toast

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...