如何替换字符串中的 Unicode 字符?
How to replace Unicode character in a string?
我需要用字符串中的 "normal" 字符替换文字 UNICODE character:
HTMLString := StringReplace(HTMLString, '??', '->', [rfReplaceAll]);
但我无法在 Delphi 代码编辑器中输入此 Unicode 字符,因为 Delphi 代码编辑器无法显示此 Unicode 字符。
我可以清楚地看到上面的 Unicode 字符在字符串中,因为当我使用 CodeSite 发送字符串时,我可以在 CodeSite Live Viewer 中看到它:
CodeSite.Send('HTMLString', HTMLString);
这是 CodeSite Live Viewer 的屏幕截图:
那么如何替换字符串中的这个 Unicode 字符呢?
Delphi:10.1 柏林
Delphi IDE 从 V2009 开始支持 Unicode
,只需在代码编辑器中右击进入 File Format
然后 select UTF8
,这是一个替换 unicode 字符的简单示例:
procedure TForm1.FormCreate(Sender: TObject);
Var
S: Char;
Str: string;
begin
S:= chr(b6); // Or S:= chr(9654);
Str:= S + 'Hi there' + S;
Caption:= Str + ' ---> ' + StringReplace(Str, S, '', [rfReplaceAll]);
end;
Among the many new features found in Delphi 2009 is the imbuing of Unicode throughout the product. The default string in Delphi is now a Unicode-based string. Since Delphi is largely built with Delphi, the IDE, the compiler, the RTL, and the VCL all are fully Unicode-enabled.
我需要用字符串中的 "normal" 字符替换文字 UNICODE character:
HTMLString := StringReplace(HTMLString, '??', '->', [rfReplaceAll]);
但我无法在 Delphi 代码编辑器中输入此 Unicode 字符,因为 Delphi 代码编辑器无法显示此 Unicode 字符。
我可以清楚地看到上面的 Unicode 字符在字符串中,因为当我使用 CodeSite 发送字符串时,我可以在 CodeSite Live Viewer 中看到它:
CodeSite.Send('HTMLString', HTMLString);
这是 CodeSite Live Viewer 的屏幕截图:
那么如何替换字符串中的这个 Unicode 字符呢?
Delphi:10.1 柏林
Delphi IDE 从 V2009 开始支持 Unicode
,只需在代码编辑器中右击进入 File Format
然后 select UTF8
,这是一个替换 unicode 字符的简单示例:
procedure TForm1.FormCreate(Sender: TObject);
Var
S: Char;
Str: string;
begin
S:= chr(b6); // Or S:= chr(9654);
Str:= S + 'Hi there' + S;
Caption:= Str + ' ---> ' + StringReplace(Str, S, '', [rfReplaceAll]);
end;
Among the many new features found in Delphi 2009 is the imbuing of Unicode throughout the product. The default string in Delphi is now a Unicode-based string. Since Delphi is largely built with Delphi, the IDE, the compiler, the RTL, and the VCL all are fully Unicode-enabled.