如何在 Delphi 中定义空字符 [英] How to define Empty Char in Delphi
问题描述
只是为了好奇,
为什么在 Delphi 中,如果我们通过以下方式定义一个空字符:
Why in Delp if we defined an empty char by:
a:Char;
a:='';
我们得到一个错误:不兼容的类型:'Char' and 'string'
但是,如果我们放置
a:='a';
会好吗?
是否需要通过a:=#0
定义一个空字符?
Is it necessary to define an empty char by: a:=#0
?
推荐答案
一个 char 是单个(即,恰好是一个)字符.所以'a'、'∫'和'⌬'都可以,但'ab'(两个字符的字符串)不行,'Hello World!'(一个十二个字符的字符串),或 ''(一个零字符的字符串).
A char is a single (that is, exactly one) character. So 'a', '∫', and '⌬' are all OK, but not 'ab' (a two-character string), 'Hello World!' (a twelve-character string), or '' (a zero-character string).
但是,NULL 字符 (#0) 与其他字符一样.
However, the NULL character (#0) is a character like any other.
此外,字符数据类型被实现为一个单词(在现代版本的 Delphi 中),即两个字节.如果所有这些值 0, 1, ..., 2^16 - 1 都用于真实字符,那么您将如何表示您的空字符"?
In addition, the character datatype is implemented as a word (in modern versions of Delphi), that is, as two bytes. If all these values 0, 1, ..., 2^16 - 1 are used for real characters, how in the world would you represent your 'empty char'?
这篇关于如何在 Delphi 中定义空字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!