Previous: , Up: Basic Editing   [Contents][Index]

3.20 Strings are not Arrays

Arrays are collections of homogeneous data organized in a sequence. We have already seen (briefly) arrays of bytes, which use the type specifier byte[].

Similarly, it is possible to arrange characters (which are basically little numbers) in an array, like in:

(poke) ['a','b','c']

However, the array above is not equivalent to the string "abc". The later is a simple value, whereas an array is a composite value, and also is implicitly terminated with a NULL character, i.e. a 0 byte.

The Poke standard library provides a couple of utility functions to convert between string values and character arrays: catos and stoca.

catos gets an array of characters and returns an equivalent string. For example:

(poke) catos (['a','b','c'])

stoca gets a string and an array and sets the element of the array to the characters composing the string. For example:

(poke) var a = char[3]()
(poke) stoca ("abc", a)
(poke) a