ListSetAt

Retrieves an item in to a delimited list at the specified position

Method Signature

ListSetAt(list=[string], position=[integer], value=[string], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean])

Arguments

Argument
Type
Required
Description
Default

list

string

true

string list to filter entries from

position

integer

true

numeric the one-based index position to retrieve the value at

value

string

true

string the value to set at the specified position

delimiter

string

false

string the list delimiter

,

includeEmptyFields

boolean

false

boolean whether to include empty fields in the returned result

false

multiCharacterDelimiter

boolean

false

boolean whether the delimiter is multi-character

true

Examples

Simple Example

Replaces the 2nd list element with 'foo'

Run Example

listSetAt( "bar,lorem,ipsum", 2, "foo" );

Result: bar,foo,ipsum

Example with Custom Delimiter

Inserts 'foo' into the list with a custom delimiter

Run Example

listSetAt( "bar|lorem,ipsum|me|something", 2, "foo", "|" );

Result: bar|foo|me|something

Additional Examples

Run Example

list1 = ",a,b,c,d,e";
Dump( listSetAt( list1, "2", "Z" ) );
list2 = ",a||b||c||d||e";
Dump( listSetAt( list2, "2", "Z", "||" ) );
list3 = ",a,b,c,d,e";
Dump( listSetAt( list3, "2", "Z", ",", true ) ); // Because it includes empty field value ,Z,b,c,d,e
// MemberFunction
dump( list1.listSetAt( "4", "Y" ) );
 // ,a,b,c,Y,e

Last updated

Was this helpful?