delphi - 任何从字符中删除重音的 RTL 函数?
问题描述
é
如今在悉尼,是否有任何 RTL 功能可以从字符串中的字符(例如变为)中删除重音e
?我知道这个问题过去已经被问过,但我想知道悉尼的答案是否仍然准确 - 我特别想找到一种适用于所有平台的功能(我现在使用的功能只能通过 WideString 和Windows API)。
解决方案
找到并修改了使用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;
推荐阅读
- c++ - 包装类的专业化
- c++ - C++宏定义了一个空数组
- excel - VBA Sum If 适用于活动工作表但与其他工作表错误
- python - 打开顶层窗口时的灰色按钮
- java - 如何用另一种类型的元素替换 java.util.List 中的元素?
- asp.net - 为什么我的 2 个 Livecharts 笛卡尔实例不起作用?
- apache-flink - Flink 从单个 jar 运行多个作业
- software-design - 如何实现开闭原则?
- typescript - 2个for循环完成后如何返回值?
- c# - 从任务管理器中终止时,Windows 服务 C# 不会在停止时调用方法