加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – ord()和字符串的问题

发布时间:2020-12-15 09:09:19 所属栏目:大数据 来源:网络整理
导读:我有这个问题,如果我有: mychr =”; mychr中的’space’等于#255(手动输入ALT 255),我写道: myord = ord(mychr) 到myord返回值160而不是255.当然,同样的问题也是charater ALT 254等. 我可以解决这个问题吗?我在控制台模式下测试了delphi xe. 注意:如果我
我有这个问题,如果我有:

mychr =”;

mychr中的’space’等于#255(手动输入ALT 255),我写道:

myord = ord(mychr)

到myord返回值160而不是255.当然,同样的问题也是charater ALT 254等.
我可以解决这个问题吗?我在控制台模式下测试了delphi xe.

注意:如果我使用:

mychar =#255;

然后函数ord()正确返回值.

解决方法

我认为问题是 Windows Alt Num快捷方式根据本地代码页插入字符,而现代Delphi使用Unicode字符,这些不同(除非值小于或等于127,我认为).解决方案是在代码中明确输入值#255.另外,在代码中包含“隐形”特殊字符是一个非常糟糕的习惯,因为如果不复制到外部工具就无法分辨出它是什么字符!此外,您必须信任.pas文件的文本编码.使用像#255这样的常量要好得多.更好的是,做

const
  MY_PRECIOUS_VALUE = #255;

并在每次需要时使用此常量.

更新

根据Alt code上的英文维基百科文章:

If the number typed has a leading 0
(zero),the character set used is the
Windows code page that matches the
current input locale. For most systems
using the Latin alphabet,this is
Windows-1252. For a complete list,see
code page. If the number does not have
a leading 0 (zero),DOS compatibility
is invoked. The character set used is
the DOS code page for the current
input locale. For systems using
English,this is code page 437. For
most other systems using the Latin
alphabet,this is code page 850. For a
complete list,see code page.

所以,如果你真的,真的想继续输入Alt键码,你最好输入Alt和0255以及前导零.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读