首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >StringGetChar和CharToStr不互换

StringGetChar和CharToStr不互换
EN

Stack Overflow用户
提问于 2019-07-16 09:29:01
回答 1查看 114关注 0票数 0

在设置字符串之后,我试图从字符串中获取一个特殊字符(ASCII >127),但是输出发生了变化,因为CharToStr接受uchar,而StringGetChar返回ushort。

这是我尝试过的:

代码语言:javascript
复制
  uchar uch = 234;

  Print(uch);    //Output:  234
  string a = CharToStr(uch);

  uch = (uchar)StringGetChar(a,0);
  Print(uch);    //Output:   218

我如何克服这个问题?

EN

回答 1

Stack Overflow用户

发布于 2019-07-22 00:41:12

我想提出我自己的答案。而不是处理uchar <==> ushort,这是由于MQL4中持续的错误造成的问题,您可以这样重新编码它:

代码语言:javascript
复制
//let's say it can be any number, unknown in compilation time
string msg = "234My message";
//then somewhere in the code when you want to display the message:
uchar arrow = (uchar)StringToInteger(StringSubstr(msg,0,3));
//and act upon this arrow, now that you have the correct code:
if(arrow==234) { ... }
else if (arrow==233)  { ... }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57048963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档