Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define Empty Char in Delphi

Just for curiosity,

Why in Delphi, if we defined an empty char by:

a:Char;
a:='';

we get an error: Incompatible types: 'Char' and 'string'

However, if we placed

a:='a';

it will be fine?

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

like image 384
Zeina Avatar asked Mar 08 '12 13:03

Zeina


People also ask

How do you make a char empty?

You can use c[i]= '\0' or simply c[i] = (char) 0 . The null/empty char is simply a value of zero, but can also be represented as a character with an escaped zero.

Can you have an empty char?

An empty char value does not belong to any char, so Java gives a compile-time error. To create an empty char, we either can assign it a null value \0 or default Unicode value \u0000 .

What is the char value for empty string?

An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.

What is a char in Delphi?

The Char type represents a single character, just as it does in standard Pascal. You can cast any integer type to a character by using the Char type name in a type cast. Unlike some other type casts, the size of the integer value does not have to match the size of a Char.


1 Answers

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

However, the NULL character (#0) is a character like any other.

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'?

like image 89
Andreas Rejbrand Avatar answered Sep 19 '22 12:09

Andreas Rejbrand