![]() | Chapter 19: Advanced Text | ![]() ![]() |
19.3. Characters, words, punctuated words, unpunctuated words, lines, paragraphs |
Suppose we have some text called, once again, WHATEVER. Inform can get at its contents in a variety of ways. The lowest-level is by character - a character is a letter, digit, punctuation symbol, space or other letter-form. (We use the term "character" rather than "letter" because otherwise we would have to call "5" a letter, and so on.) Characters number upwards from 1: character number 1, to repeat that, starts the text. We can get the Nth character with:
character number N in WHATEVER
The maximum character number varies with the current length of the text, and can be evaluated as:
number of characters in WHATEVER
For instance, the number of characters in "gazette" is 7, and the number of characters in "" is 0. (When that happens, an indexed text is "empty", just as for ordinary text; and otherwise it is "non-empty".)
We can also extract the contents by word, again numbered from 1. Thus:
word number N in WHATEVER
number of words in WHATEVER
This is trickier than it looks, though, because what do we mean by word, exactly? The answer is: what's left after breaking the text up at punctuation or spacing (spaces, line breaks, paragraph breaks) and then removing that punctuation or spacing. So the number of words in "ice-hot, don't you think?" is 5: "ice", "hot", "don't", "you", "think". (Note that the contraction apostrophe in "don't" doesn't count as punctuation.) Because this is not always quite what we want, Inform offers two variations:
punctuated word number N in WHATEVER
number of punctuated words in WHATEVER
unpunctuated word number N in WHATEVER
number of unpunctuated words in WHATEVER
The punctuated words in "ice-hot, don't you think?" are "ice", "-", "hot", ",", "don't", "you", "think", "?". If two or more punctuation marks are adjacent, they are counted as different words, except for runs of dashes or periods: thus ",," has two punctuated words, but "--" and "..." have only one each. The unpunctuated words in "ice-hot, don't you think?" are "ice-hot,", "don't", "you", "think?" - here we are breaking words only at spacing, and treating punctuation as just another kind of letter.
Finally, on the larger scale still, we also have
line number N in WHATEVER
number of lines in WHATEVER
paragraph number N in WHATEVER
number of paragraphs in WHATEVER
Unless explicit use is made of line-breaking, lines and paragraphs will be the same - it doesn't refer to lines as visible on screen, because we have no way of knowing what size screen the player might have. But for instance
"Sensational news just in![paragraph break]The Martians have invaded Miranda.[line break](One of the moons of Uranus, that is.)"
has two paragraphs, but three lines.
(Attempting to make large enough texts to have a serious paragraph count is slightly risky if there is not much memory to play with, as on the Z-machine. But the facilities do exist.)
Previous | Contents | Next |