Type conversion: Char to string

The programming language Chora supports the data type string to represent text and the data type char to represent single UNICODE characters. In order to convert a char operand in a string an adequate conversion operator is available. The conversion operator is implemented as an instant constructor of the data type string.

Explicit conversion

With the explicit conversion you specify explicitly how the char operand should be converted in a string. The for this purpose used instant constructor permits you to specify in an optional parameter the desired number of character copies in the resulting string. For example:

var int32 a = '*'; var string b1 = string( a ); // b1 = "*" var string b2 = string( a, 5 ); // b2 = "*****"

Implicit conversion

Wherever it is not ambiguous, the Chora compiler applies the necessary type conversion implicitly. This is usually the case when you assign the result of an expression to e.g. a variable or you pass it as parameter in a method invocation. In such cases the Chora compiler can derive from the destination operand the corresponding data type and decide whether or not to convert the expression.

For example, the following assignment implies the conversion from char to string data type since the destination operand str is a local variable declared with string as data type:

var char a = '*'; var string str; // Apply an implicit conversion from 'char' to 'string' str = a; // str = "*"