首页 > 解决方案 > 任何从字符中删除重音的 RTL 函数?

问题描述

é如今在悉尼,是否有任何 RTL 功能可以从字符串中的字符(例如变为)中删除重音e?我知道这个问题过去已经被问过,但我想知道悉尼的答案是否仍然准确 - 我特别想找到一种适用于所有平台的功能(我现在使用的功能只能通过 WideString 和Windows API)。

标签: delphifiremonkeyunicode-normalization

解决方案


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

delphi如何使用NormalizeString函数?

这在 Delphi 10.3 Rio 中对我有用(包括System.Character在您的uses条款中):

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;

推荐阅读