如何在Delphi中定义空字符 [英] How to define Empty Char in Delphi

查看:378
本文介绍了如何在Delphi中定义空字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,

为什么在Delphi中,如果我们通过以下方式定义空字符:

Why in Delp if we defined an empty char by:

a:Char;
a:='';

我们得到一个错误:不兼容的类型:'Char'和'string'

但是,如果我们放置

a:='a';

会很好吗?

是有必要通过以下方式定义一个空字符: a:=#0

Is it necessary to define an empty char by: a:=#0?

推荐答案

字符是一个(即正好一个)字符。因此, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆