User Tools

Site Tools


harlowe:string

Differences

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

Link to this comparison view

harlowe:string [2017/10/09 20:39]
harlowe:string [2017/10/09 20:39] (current)
Line 1: Line 1:
 +====String data====
 +A string is just a block of text - a bunch of text characters strung together.
  
 +When making a story, you'll mostly work with strings that you intend to insert into
 +the passage source. If a string contains markup, then the markup will be processed when it's
 +inserted. For instance, ''​%%"​The ''​biiiiig''​ bellyblob"​%%''​ will print as "The <​html><​b></​html>​biiiiig<​html></​b></​html>​ bellyblob"​.
 +Even macro calls inside strings will be processed: printing ''​%%"​The (print:2*3) bears"​%%''​ will print "The 6 bears"​.
 +If you wish to avoid this, simply include the verbatim markup inside the string:''​%%"​`It'​s (exactly: as planned)`"​%%''​ will
 +print "​It'​s (exactly: as planned)"​.
 +
 +You can add strings together to join them: ''​%%"​The"​ + ' former ' + "Prime Minister'​s"​%%''​
 +pushes the strings together, and evaluates to "The former Prime Minister'​s"​. Notice
 +that spaces had to be added between the words in order to produce a properly spaced final string.
 +Also, notice that you can only add strings together. You can't subtract them, much less multiply or divide them.
 +
 +Strings are similar to [[harlowe:​Array|Array]],​ in that their individual characters can be accessed: ''​%%"​ABC"'​s 1st%%''​ evaluates to "​A",​
 +''​%%"​Gosh"'​s 2ndlast%%''​ evaluates to "​s",​ and ''​%%"​Exeunt"'​s last%%''​ evaluates to "​t"​. They, too, have a "​length":​
 +''​%%"​Marathon"'​s length%%''​ is 8. If you don't know the exact position of a character, you can use an expression,
 +in brackers, after it: ''​%%$string'​s ($pos - 3)%%''​. And, you can access a substring by providing an array of positions
 +in place of a single position: ''​%%"​Dog"'​s (a: 2,​3)%%''​ is "​og"​.
 +
 +Also, you can use the ''​%%contains%%''​ and ''​%%is in%%''​ operators to see if a certain string is contained within another: ''​%%"​mother"​ contains "​moth"​%%''​ is true, as is ''​%%"​a"​ is in "​a"​%%''​. Again, like arrays, strings have special ''​%%any%%''​ and ''​%%all%%''​ data names which
 +can be used with ''​%%contains%%''​ and ''​%%is in%%''​ to check all their characters - ''​%%all of $string is not "​w"​%%''​ is true if the string doesn'​t
 +contain "​w",​ and ''​%%$string contains any of "​aeiou"​%%''​ is true if the string contains those five letters.
 +
 +To summarise, here are the operations you can perform on strings.
 +
 +^Operator ​       ^ Meaning ^ Example ^
 +| ''​+''​ | Joining. | ''"​A"​ + "​Z"''​ (is "​AZ"​)|
 +| ''​is''​ | Evaluates to boolean ''​true''​ if both sides are equal, otherwise ''​false''​. | ''​$name is "​Frederika"'',​ ''​any of "​Buxom"​ is "​x"''​|
 +| ''​is not''​ | Evaluates to boolean ''​true''​ if both sides are not equal, otherwise ''​false''​. | ''​$friends is not $enemies'',​ ''​all of "​Gadsby"​ is not "​e"''​|
 +| ''​contains''​ | Evaluates to boolean ''​true''​ if the left side contains the right side, otherwise ''​false''​. | ''"​Fear"​ contains "​ear"''​|
 +| ''​is in''​ | Checking if the right string contains the left string, otherwise ''​false''​. | ''"​ugh"​ is in "​Through"''​|
 +| '''​s''​ | Obtaining the character or substring at the right numeric position. | ''"​YO"'​s 1st''​ (is "​Y"​),​ ''"​PS"'​s (2)''​ (is "​S"​),​ ''"​ear"'​s (a: 2,​3)''​ (is "​ar"​)|
 +| ''​of''​ | Obtaining the character at the left numeric position. | ''​1st of "​YO"''​ (is "​Y"​),​ ''​(2) of "​PS"''​ (is "​S"​),​ ''​(a:​ 2,3) of "​ear"''​ (is "​ar"​)|
harlowe/string.txt ยท Last modified: 2017/10/09 20:39 (external edit)