User Tools

Site Tools


harlowe:words

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

harlowe:words [2017/10/09 20:39] (current)
Line 1: Line 1:
 +**(words: // [[harlowe:​String|String]]//​) -> //​[[harlowe:​Array|Array]]//​**
  
 +This macro takes a [[harlowe:​string|string]] and creates an [[harlowe:​Array|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:​startcase|(startcase:​)]]
harlowe/words.txt ยท Last modified: 2017/10/09 20:39 (external edit)