listReplace: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page ListReplace to listReplace: Converting page titles to lowercase)
No edit summary
 
Line 6: Line 6:


|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>


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


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


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