首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有什么RTL函数可以去除字符中的重音?

问有没有什么RTL函数可以去除字符中的重音?
EN

Stack Overflow用户
提问于 2021-03-21 22:50:55
回答 1查看 159关注 0票数 1

如今在悉尼,有没有什么RTL函数可以去除字符串中字符的重音(例如,é变成了e )?我知道这个问题在过去已经被问过了,但我想知道悉尼的答案是否仍然准确-我特别喜欢找到一个在所有平台上都能工作的函数(我现在使用的那个函数只能通过WideString和Windows API工作)。

EN

回答 1

Stack Overflow用户

发布于 2021-03-22 19:30:00

找到并修改了本文中使用NormalizeString()的实现:

How to use NormalizeString function in delphi?

这在Delphi10.3RIO中适用(在uses子句中包含System.Character ):

代码语言:javascript
复制
function NormalizeString(NormForm: NORM_FORM; lpSrcString: LPCWSTR; cwSrcLength: Integer; lpDstString: LPWSTR; cwDstLength: Integer): Integer; stdcall; external 'C:\WINDOWS\system32\normaliz.dll';
    
function NormalizeText(Str: string): string;
var
  nLength: integer;
  c: char;
  i: integer;
  temp: string;
  CatStr:string;
begin
  nLength := NormalizeString(NormalizationD, PChar(Str), Length(Str), nil, 0);
  SetLength(temp, nLength);

  nLength := NormalizeString(NormalizationD, PChar(Str), Length(Str), PChar(temp), nLength);
  SetLength(temp, nLength);

  CatStr:='';
  for i := 1 to length(temp) do
  begin
    c:=temp[i];
    if (TCharacter.GetUnicodeCategory(c) <> TUnicodeCategory.ucNonSpacingMark) and
      (TCharacter.GetUnicodeCategory(c) <> TUnicodeCategory.ucCombiningMark) then
      CatStr:=CatStr+c;
  end;
  result:=CatStr;
end;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66733768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档