将角度符号添加到字符串

Add angle symbol to string

如何将 angle symbol 添加到字符串以放入 TMemo

我可以根据 extended ascii table:

中的八进制值轻松添加度数符号
String deg = "2";  // 272 is octal value in ascii code table for degree symbol
Form1->Memo1->Lines->Add("My angle = 90" + deg);

但是,如果我 尝试使用角度符号的转义序列 (\u2220),我会得到一个编译器错误,W8114 Character represented by universal-character-name \u2220 cannot be represented in the current ansi locale:

UnicodeString deg = "\u2220";
Form1->Memo1->Lines->Add("My angle = 90" + deg);

为清楚起见,下面是我要查找的符号。我可以只使用 @ 如果我也有,只是想知道这是否可能而不会咬牙切齿。我的测试目标是 Win32,但我希望它也能在 iOS 和 Android 上运行。

p.s。 This table 方便看代码。

After 在 Rob 的回答之后,我已经开始工作了,但是在 iOS 上,角度与其他文本一起向下偏移到水平线以下。在 Win32 上它很小。在 Android 上看起来不错。我将作为错误报告给 Embarcadero,尽管是小错误。

这是我根据 Rob 的评论使用的代码:

UnicodeString szDeg;
UnicodeString szAng;
szAng.SetLength(1);
szDeg.SetLength(1);
*(szAng.c_str()) = 0x2220;
*(szDeg.c_str()) = 0x00BA;
Form1->Memo1->Lines->Add("1: " + FormatFloat("##,###0.0",myPhasors.M1)+ szAng + FormatFloat("###0.0",myPhasors.A1) + szDeg);

下面是将 TMemo 字体明确设置为 Courier New 时的样子:

这是我在 Remy 回复后使用的最终代码:

UnicodeString szAng = _D("\u2220");         
UnicodeString szDeg = _D("\u00BA");
Form1->Memo1->Lines->Add("1: " + FormatFloat("##,###0.0",myPhasors.M1)+ szAng + FormatFloat("###0.0",myPhasors.A1) + szDeg);

该错误表示某种代码范围错误,您应该能够避免。直接设置字符编码试试:

UnicodeString  szDeg;
UnicodeString  szMessage;

  szDeg.SetLength(1);
  *(szDeg.c_str())=0x2022;

  szMessage=UnicodeString(L"My angle = 90 ")+szDeg;
  Form1->Memo1->Lines->Add(szMessage);

编译器错误是因为您使用的是窄 ANSI 字符串文字,并且 \u2220 不适合 char。请改用 Unicode 字符串文字:

UnicodeString deg = _D("\u2220");

RTL 的 _D() 宏根据 UnicodeString 是否使用 wchar_t(Windows 或 char16_t (其他平台)用于其字符数据。