代码之家  ›  专栏  ›  技术社区  ›  user1580348

如何替换字符串中的Unicode字符?

  •  0
  • user1580348  · 技术社区  · 6 年前

    UNICODE character 字符串中包含“普通”字符:

    HTMLString := StringReplace(HTMLString, '??', '->', [rfReplaceAll]);
    

    但是我不能在Delphi代码编辑器中输入这个Unicode字符,因为Delphi代码编辑器不能显示这个Unicode字符。

    我可以清楚地看到上面的Unicode字符在字符串中,因为当我用CodeSite发送字符串时,我可以在CodeSite Live Viewer中看到它:

    CodeSite.Send('HTMLString', HTMLString);
    

    这是CodeSite Live Viewer的屏幕截图:

    enter image description here

    德尔福:10.1柏林

    1 回复  |  直到 6 年前
        1
  •  3
  •   Ilyes    6 年前

    Delphi IDE支持 Unicode 从V2009开始,只需在代码编辑器中单击鼠标右键 File Format 然后选择 UTF8

    procedure TForm1.FormCreate(Sender: TObject);
    Var
     S: Char;
     Str: string;
    begin
      S:= chr($25b6); // Or S:= chr(9654);
      Str:= S + 'Hi there' + S;
      Caption:= Str + ' ---> ' + StringReplace(Str, S, '', [rfReplaceAll]);
    end;
    

    在Delphi2009中发现的许多新特性中,包括在整个产品中嵌入Unicode。Delphi中的默认字符串现在是基于Unicode的字符串。由于Delphi主要是用Delphi构建的,因此IDE、编译器、RTL和VCL都完全支持Unicode。

    阅读所有文章: http://edn.embarcadero.com/article/38437