indexOf: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function indexOf== {{ProposedChange}} Returns the index of a substring in the specified string. If the substring does not occur within the string then -1 is returned. If you do not speci...)
 
No edit summary
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Function indexOf==
{{MacroFunction
{{ProposedChange}}
|name=indexOf
Returns the index of a substring in the specified string. If the substring does not occur within the string then -1 is returned. If you do not specify the index to start at the search begins at the start of the string otherwise it will begin from the position you specify. [[Macros:regular expressions|regular expressions]] can be used in the substring.
|version=1.3b48
|description=
Returns the index of a substring in the specified string. If the substring does not occur within the string then -1 is returned. If you do not specify the index to start at the search begins at the start of the string otherwise it will begin from the position you specify.


===Usage===
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: ind = index(str, substr)]
indexOf(str, substr)
[h: ind = index(str, substr, start)]
</syntaxhighlight>
</source>
<syntaxhighlight lang="mtmacro" line>
indexOf(str, substr, start)
</syntaxhighlight>


 
|examples=
===Examples===
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[r: indexOf("this is a test", "is")]
[r: indexOf("this is a test", "is")]
</source>
</syntaxhighlight>
Returns 2.
Returns 2.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: indexOf("this is a test", "is", 3)]
[r: indexOf("this is a test", "is", 3)]
</source>
</syntaxhighlight>
Returns 5.
Returns 5.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: indexOf("this is a test", "x")]
[r: indexOf("this is a test", "x")]
</source>
</syntaxhighlight>
Returns -1.
Returns -1.
}}
[[Category:String Function]]

Latest revision as of 23:59, 15 March 2023

indexOf() Function

Introduced in version 1.3b48
Returns the index of a substring in the specified string. If the substring does not occur within the string then -1 is returned. If you do not specify the index to start at the search begins at the start of the string otherwise it will begin from the position you specify.

Usage

indexOf(str, substr)
indexOf(str, substr, start)

Examples

[r: indexOf("this is a test", "is")]

Returns 2.

[r: indexOf("this is a test", "is", 3)]

Returns 5.

[r: indexOf("this is a test", "x")]
Returns -1.