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;


function GetPYFirst(cnStr: string): string;
var
  i: Integer;
  p: string[4];
  tmpStr: string;
begin
  Result := '';
  for i := 0 to Length(cnStr) - 1 do
  begin
    tmpStr := AnsiRightStr(cnStr, Length(cnStr) - i);
    p := AnsiLeftStr(tmpStr, 1);

    // ShowMessage(p);
    Result := Result + GetCharSpellCode(p);
  end;
end;

相关阅读 >>

Delphi kbmmw安装

Delphi下载程序并且urldownloadtofile的进度提示

Delphi 两个exe之间共享数据

Delphi 字符串截取

Delphi 数字分隔

Delphi xe 在andriod程序中获取外置sd卡根目录

Delphi 将jpg图片上传到sqlserver数据库里

Delphi idhttp中get 图像链接通过memorystream加载 image控件显示

Delphi randomize 随机数

Delphi 下载者源代码

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



打赏

取消

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

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

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

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

评论

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