stringToList: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Applied Template:MacroFunction)
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{MacroFunction
{{MacroFunction
|name=stringToList
|name=stringToList
|version=1.3b48
|description=
|description=
Converts a string into a [[Macros:string list|string list]] using a pattern to determine separator between elements. The specified delimiter is used to separate the elements in the [[Macros:string list]] if it is specified, otherwise the default value of "," is used.  Pattern can be a [[Macros:regular expression|regular expression]].
Converts a string into a [[Macros:string list|string list]] using a pattern to determine separator between elements. The specified delimiter is used to separate the elements in the [[Macros:string list]] if it is specified, otherwise the default value of "," is used.  Pattern can be a [[Macros:regular expression|regular expression]].


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro">
[h: list = stringToList(str, pattern)]
stringToList(str, pattern)
[h: list = stringToList(str, pattern, delim)]
stringToList(str, pattern, delim)
</source>
</syntaxhighlight>
 
'''Parameters'''
{{param|str|Variable name of a string to convert.}}
{{param|pattern|The pattern to split the line by.}}
{{param|delim|Option delimiter for output. Defaults to ",".}}


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
    [stringToList("This is a test", " ")]
[stringToList("This is a test", " ")]
    [stringToList("1,2,3,4", ",", ":")]
[stringToList("1,2,3,4", ",", ":")]
</source>
</syntaxhighlight>
Returns  
Returns  
    This,is,a,test
<syntaxhighlight lang="mtmacro">
    1:2:3:4
This,is,a,test
1:2:3:4
</syntaxhighlight>
}}
}}
[[Category:String List Function]]
[[Category:String List Function]]

Latest revision as of 23:59, 14 March 2023

stringToList() Function

Introduced in version 1.3b48
Converts a string into a string list using a pattern to determine separator between elements. The specified delimiter is used to separate the elements in the Macros:string list if it is specified, otherwise the default value of "," is used. Pattern can be a regular expression.

Usage

stringToList(str, pattern)
stringToList(str, pattern, delim)

Parameters

  • str - Variable name of a string to convert.
  • pattern - The pattern to split the line by.
  • delim - Option delimiter for output. Defaults to ",".

Examples

[stringToList("This is a test", " ")]
[stringToList("1,2,3,4", ",", ":")]

Returns

This,is,a,test
1:2:3:4