listGet: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 4: Line 4:
|description=
|description=
Returns the value in the [[Macros:string list|string list]] at the specified index. The index for a [[Macros:string list|string list]] starts at 0.
Returns the value in the [[Macros:string list|string list]] at the specified index. The index for a [[Macros:string list|string list]] starts at 0.
Known Bug: If you use a whitespace character like a SPACE or TAB, listGet will pull the wrong indexed value.
<source lang="mtmacro" line>
[H: a = "1 2  4 5"]
[r: listGet(a,3," ")]
</source>
Output is 5, when it should be 4 because of the 2 SPACE characters counting as 1.


|usage=
|usage=
Line 26: Line 19:
[r: listGet("This, is, a , test", 2)]
[r: listGet("This, is, a , test", 2)]
</source>
</source>
Returns a
Returns {{code|a}}


<source lang="mtmacro" line>
<source lang="mtmacro" line>
[r: listGet("This: is: a :test", 1, ":")]  
[r: listGet("This: is: a :test", 1, ":")]  
</source>
</source>
Returns is
Returns {{code|is}}
 
===Known Bug===
If you use a whitespace character like a SPACE or TAB, listGet can pull the wrong indexed value.
<source lang="mtmacro" line>
[h: list = "0 1  3 4"]
[r: listGet(list, 3, " ")]
</source>
The output should be 3, but it is 4 because of the two SPACE characters being treated as one. Consequently this skips over an empty entry.
}}
}}
[[Category:String List Function]]
[[Category:String List Function]]

Revision as of 12:13, 3 January 2022

listGet() Function

Introduced in version 1.3b42
Returns the value in the string list at the specified index. The index for a string list starts at 0.

Usage

listGet(list, index)
listGet(list, index, delim)

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

Example

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

Returns a

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

Returns is

Known Bug

If you use a whitespace character like a SPACE or TAB, listGet can pull the wrong indexed value.

[h: list = "0 1  3 4"]
[r: listGet(list, 3, " ")]
The output should be 3, but it is 4 because of the two SPACE characters being treated as one. Consequently this skips over an empty entry.