User Tools

Site Tools


Sidebar

Passage markup

basics

coding

extra

list

section

whitespace

Macros

basics

colour

data structure

date and time

game state

live

maths

number

revision

saving

showing and hiding

string

styling

url

deprecated

Types of data

Special keywords

Special passage tags

harlowe:words

(words: String) → Array

This macro takes a string and creates an Array of each word (“word” meaning a sequence of non-whitespace characters) in the string.

Example usage:

(words: "god-king Torment's peril") is the same as (a: "god-king", "Torment's", "peril")

Rationale:

It can be useful to explicitly distinguish individual words within a string, in a manner not possible with just the contains operator - for instance, seeing if a string contains the bare word “to” - not “torn” or any other larger word. This macro allows a string's words to be split up and examined individually - you can safely check if (words: $a) contains "to", or check on a particular word in the sequence by asking if, say, (words: $a)'s 2nd is 'goose'.

Details:

If the string was empty or contained only whitespace, then this will create an empty array. Moreover, if the string contained no whitespace, then the array will contain just the entire original string.

The whitespace characters recognised by this macro include line breaks, non-breaking spaces, and other uncommon space characters.

See also:

harlowe/words.txt · Last modified: 2017/06/18 22:53 by l