listFind: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function listFind== Returns the index of the first occurrence of a value in a string list. If the value is not found then -1 is returned. ===Usage=== <source lan...)
 
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Function listFind==
{{MacroFunction
 
|name=listFind
|version=1.3b42
|description=
Returns the index of the first occurrence of a value in a [[Macros:string list|string list]]. If the value is not found then -1 is returned.
Returns the index of the first occurrence of a value in a [[Macros:string list|string list]]. If the value is not found then -1 is returned.


===Usage===
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: ind = listIndex(list, value)]
listFind(list, value)
[h: ind = listIndex(list, value, delim)]
</syntaxhighlight>
</source>
<syntaxhighlight lang="mtmacro" line>
listFind(list, value, delim)
</syntaxhighlight>


If delim is not specified then the default value of ',' is used as the value separator in the [[Macros:string list|string list]]
If delim is not specified then the default value of ',' is used as the value separator in the [[Macros:string list|string list]]


===Example===
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: listFind("This, is, a, test", "is")]
[r: listFind("This, is, a, test", "is")]
</source>
</syntaxhighlight>
Returns 1
Returns 1


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: listFind("This: is: a: test", "a", ":")]
[r: listFind("This: is: a: test", "a", ":")]
</source>
</syntaxhighlight>
Returns 2
Returns 2


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: listFind("This, is, a, test", "not")]
[r: listFind("This, is, a, test", "not")]
</source>
</syntaxhighlight>
Returns -1
Returns -1
}}
[[Category:String List Function]]

Latest revision as of 17:50, 15 March 2023

listFind() Function

Introduced in version 1.3b42
Returns the index of the first occurrence of a value in a string list. If the value is not found then -1 is returned.

Usage

listFind(list, value)
listFind(list, value, delim)

If delim is not specified then the default value of ',' is used as the value separator in the string list

Examples

[r: listFind("This, is, a, test", "is")]

Returns 1

[r: listFind("This: is: a: test", "a", ":")]

Returns 2

[r: listFind("This, is, a, test", "not")]
Returns -1