如今在悉尼,有没有什么RTL函数可以去除字符串中字符的重音(例如,é变成了e )?我知道这个问题在过去已经被问过了,但我想知道悉尼的答案是否仍然准确-我特别喜欢找到一个在所有平台上都能工作的函数(我现在使用的那个函数只能通过WideString和Windows API工作)。
发布于 2021-03-22 19:30:00
找到并修改了本文中使用NormalizeString()的实现:
How to use NormalizeString function in delphi?
这在Delphi10.3RIO中适用(在uses子句中包含System.Character ):
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;https://stackoverflow.com/questions/66733768
复制相似问题