lastIndexOf: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Function lastIndexOf==
{{MacroFunction
 
|name=lastIndexOf
|version=1.3b48
|description=
Finds the index in a string of the last occurrence of a substring in a string. If the substring does not occur in the string then -1 is returned. The index for the string starts at 0.
Finds the index in a string of the last occurrence of a substring in a string. If the substring does not occur in the string then -1 is returned. The index for the string starts at 0.


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


===Example===
|example=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[lastIndexOf("abcde", "c")]
[lastIndexOf("abcde", "c")]
</source>
</syntaxhighlight>
Returns 2
Returns 2


<source lang="mtmacro" line>
<syntaxhighlight  lang="mtmacro" line>
[lastIndexOf("abcde", "z")]
[lastIndexOf("abcde", "z")]
</source>
</syntaxhighlight>
Returns -1
Returns -1
}}
[[Category:String Function]]

Latest revision as of 23:59, 15 March 2023

lastIndexOf() Function

Introduced in version 1.3b48
Finds the index in a string of the last occurrence of a substring in a string. If the substring does not occur in the string then -1 is returned. The index for the string starts at 0.

Usage

lastIndexOf(str, substr)

Example

[lastIndexOf("abcde", "c")]

Returns 2

[lastIndexOf("abcde", "z")]
Returns -1