listReplace: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 3: Line 3:
|version=1.3b42
|version=1.3b42
|description=
|description=
Replaces the element at the specified index of a [[Macros:string list|string list]] with a new value. If a delimiter is not specified then the default value of ',' is used. The index for lists starts at 0
Replaces the element at the specified index of a [[String List]] with a new value. If a delimiter is not specified then the default value of {{code|","}} is used. The index for lists starts at {{code|0}}.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
listReplace(list, index, value)
listReplace(list, index, value)
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
listReplace(list, index, value, delim)
listReplace(list, index, value, delim)
</source>
</syntaxhighlight>


|example=
|examples=
<source lang="mtmacro" line>
'''Simple example:'''
<syntaxhighlight lang="mtmacro" line>
[r: listReplace("This, isnt, a , test", 1, "is")]
[r: listReplace("This, isnt, a , test", 1, "is")]
</source>
</syntaxhighlight>
Returns This, is, a, Test
Returns {{code|This, is, a, Test}}


<source lang="mtmacro" line>
'''Example using a [[String List]] with a non-default delimiter:'''
<syntaxhighlight lang="mtmacro" line>
[r: listReplace("This: isnt: a: test", 1, "is", ":")]  
[r: listReplace("This: isnt: a: test", 1, "is", ":")]  
</source>
</syntaxhighlight>
Returns This: is: a: test
Returns {{code|This: is: a: test}}


<source lang="mtmacro" line>
'''Example using a [[String List]] stored in a variable:'''
[h: List="This, is, a, great, test"]
<syntaxhighlight lang="mtmacro" line>
[h: List=listReplace(List, 3, "poor")]
[h: ListVar = "This, is, a, great, test"]
[r: List]
[h: ListVar = listReplace(ListVar, 3, "silly")]
</source>
[r: ListVar]
Returns: This, is, a, poor, test
</syntaxhighlight>
Returns: {{code|This, is, a, silly, test}}
}}
}}
[[Category:String List Function]]
[[Category:String List Function]]

Latest revision as of 20:08, 15 March 2023

listReplace() Function

Introduced in version 1.3b42
Replaces the element at the specified index of a String List with a new value. If a delimiter is not specified then the default value of "," is used. The index for lists starts at 0.

Usage

listReplace(list, index, value)
listReplace(list, index, value, delim)

Examples

Simple example:
[r: listReplace("This, isnt, a , test", 1, "is")]

Returns This, is, a, Test

Example using a String List with a non-default delimiter:

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

Returns This: is: a: test

Example using a String List stored in a variable:

[h: ListVar = "This, is, a, great, test"]
[h: ListVar = listReplace(ListVar, 3, "silly")]
[r: ListVar]
Returns: This, is, a, silly, test