19.1. Ordinary text and indexed text

| Chapter 19: Advanced Text |

| 19.1. Ordinary text and indexed text

So far, we have dealt with text as something which comes in little packets: we have printed it out, read it in from the keyboard, and compared it with other text. But we have never tried to open the packets and get at the contents, letter by letter, or to make any alterations, or look for certain combinations of letters. These tricks are surprisingly seldom needed - a surprise, that is, given that everything Inform does is textual - but they are in fact open to us.

Inform has two kinds of value for text: the one called simply "text", and another not mentioned until now called "indexed text". Indexed text is so called because it can be accessed by index - that is, we can if we wish get at or modify character number 1, character number 2, and so on. (1, 2, ... is the index number: this is not anything to do with a project's Index.) Text and indexed text are stored in fundamentally different ways, but Inform manages the difference automatically, and very often we can forget it. For instance:

> if character number 2 in WHATEVER is "a", ...

clearly needs WHATEVER to be indexed - otherwise there would be no way to get at its second letter. But Inform notices this and automatically converts WHATEVER in order to make the test. So, for instance, faced with

> if character number 1 in "[score]" is "7", ...

Inform notices that "[score]", which is a text, is being used in a situation where indexed text is needed, and ensures that it is converted before use.

Previous | Contents | Next