简体   繁体   English

在字符串中添加角度符号

[英]Add angle symbol to string

How can i add an angle symbol to a string to put in a TMemo ? 如何在字符串中添加角度符号以放入TMemo

I can add a degree symbol easy enough based on its octal value from the extended ascii table : 我可以根据扩展的ascii表中的八进制值轻松添加度符号:

String deg = "\272";  // 272 is octal value in ascii code table for degree symbol
Form1->Memo1->Lines->Add("My angle = 90" + deg);

But, if i try to use the escape sequence for the angle symbol ( \∠ ) i get a compiler error, W8114 Character represented by universal-character-name \∠ cannot be represented in the current ansi locale : 但是,如果尝试对角符号( \∠ )使用转义序列, \∠出现编译器错误, W8114 Character represented by universal-character-name \∠ cannot be represented in the current ansi locale

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

Just for clarity, below is the symbol i'm after. 为了清楚起见,下面是我所追求的符号。 I can just use the @ if i have too, just wondering if this is possible without nashing of teeth. 如果可以的话,我也可以使用@ ,只是想知道是否有可能不咬牙。 My target for this test was Win32 but i'll want it to work on iOS and Android too. 我的测试目标是Win32,但我希望它也能在iOS和Android上运行。

在此处输入图片说明

ps This table is handy to see the codes. ps 此表便于查看代码。

After following Rob's answer i've got it working but on iOS the angle is offset down below the horizontal with the other text. 遵循Rob的回答后,我已经开始使用它,但是在iOS上,其他文本的角度向下偏移到水平线以下。 On Win32 it is tiny. 在Win32上,它很小。 Looks good on Android. 在Android上看起来不错。 I'll report as a bug to Embarcadero, albeit minor. 我将作为错误报告给Embarcadero,尽管较小。

结果

android结果

Here is code i used based on Rob's comments: 这是我根据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);

Here is how looks when explicitly set the TMemo font to Courier New: 这是将TMemo字体显式设置为Courier New时的外观:

将字体设置为Courier New之后

Here is the final code i'm using after Remy's replies: 这是雷米答复后我使用的最终代码:

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);

The compiler error is because you are using a narrow ANSI string literal, and \∠ does not fit in a char . 编译器错误是因为您使用的是窄ANSI字符串文字,并且\∠不适合char Use a Unicode string literal instead: 请改用Unicode字符串文字:

UnicodeString deg = _D("\u2220");

The RTL's _D() macro prefixes the literal with either the L or u prefix depending on whether UnicodeString uses wchar_t (Windows only) or char16_t (other platforms) for its character data. RTL的_D()宏使用Lu前缀为文字加上前缀,具体取决于UnicodeString使用wchar_t (仅限Windows)还是char16_t (其他平台)为其字符数据。

The error indicates some kind of code range failure, which you ought to be able to avoid. 该错误指示某种代码范围故障,您应该能够避免这种情况。 Try setting the character code directly: 尝试直接设置字符代码:

UnicodeString  szDeg;
UnicodeString  szMessage;

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM