User Tools

Site Tools



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

Link to this comparison view

harlowe:substring [2017/10/09 20:39] (current)
Line 1: Line 1:
 +<note important>​This macro is deprecated - it may be removed in a future release of Harlowe.</​note>​
 +**(substring:​ // [[harlowe:​String|String]],​ [[harlowe:​Number|Number]],​ Number//) -> //​String//​**
 +This macro produces a substring of the given [[harlowe:​string|string]],​ cut from two inclusive [[harlowe:​number|number]] positions.
 +=== Example usage: ===
 +''​%%(substring:​ "​growl",​ 3, 5)%%''​ is the same as ''​%%"​growl"'​s (a:​3,​4,​5)%%''​
 +=== Rationale: ===
 +You can obtain substrings of strings without this macro, by using the ''​%%'​s%%''​ or ''​%%of%%''​ syntax along
 +with an [[harlowe:​Array|Array]] of positions. For instance, ''​%%$str'​s (range:​4,​12)%%''​ obtains a substring of $str containing
 +its 4th through 12th characters. But, for compatibility with previous Harlowe versions which did not
 +feature this syntax, this macro also exists.
 +=== Details: ===
 +If you provide negative numbers, they will be treated as being offset from the end
 +of the string - ''​%%-2%%''​ will specify the ''​%%2ndlast%%''​ character, just as 2 will specify
 +the ''​%%2nd%%''​ character.
 +If the last number given is smaller than the first (for instance, in ''​%%(substring:​ "​hewed",​ 4, 2)%%''​)
 +then the macro will still work - in that case returning "​ewe"​ as if the numbers were in
 +the correct order.
 +=== See also: ===
harlowe/substring.txt ยท Last modified: 2017/10/09 20:39 (external edit)