substring: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function substring== Returns the substring of the string from the start to the end indexes. Indexes for strings start at 0. If the end parameter is not specified then the substring exte...)
 
m (Added note re: negative indexes)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function substring==
{{MacroFunction
|name=substring
|version=1.3b48
|description=
Returns the substring of the string from the start to the end indexes. Indexes for strings start at 0. Negative indexes count from the end of the string; the index {{code|-1}} is equivalent to the last character.  If the end parameter is not specified, then the substring extends to the end of the string.


Returns the substring of the string from the start to the end indexes. Indexes for strings start at 0. If the end parameter is not specified then the substring extends to the end of the string.
|usage=
<syntaxhighlight lang="mtmacro" line>
substring(str, start)
</syntaxhighlight>
<syntaxhighlight lang="mtmacro" line>
substring(str, start, end)
</syntaxhighlight>


===Usage===
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: str = substring(str,  start)]
[h: str = substring(str, start, end)]
</source>
 
 
===Example===
<source lang="mtmacro" line>
     [substring("This is a test", 5)]
     [substring("This is a test", 5)]
     [substring("This is a test", 5, 7)]
     [substring("This is a test", 5, 7)]
</source>
</syntaxhighlight>
Returns  
Returns  
<pre>
     is a test
     is a test
     is
     is
</pre>
}}
[[Category:String Function]]

Latest revision as of 07:06, 27 November 2023

substring() Function

Introduced in version 1.3b48
Returns the substring of the string from the start to the end indexes. Indexes for strings start at 0. Negative indexes count from the end of the string; the index -1 is equivalent to the last character. If the end parameter is not specified, then the substring extends to the end of the string.

Usage

substring(str, start)
substring(str, start, end)

Examples

    [substring("This is a test", 5)]
    [substring("This is a test", 5, 7)]

Returns

    is a test
    is