string_join_ext

This function joins together the string representations of all values in the given array (or part of the array), inserting the given "delimiter" between each value. The function returns the joined string.

Values that are not strings will have the string() function run on them implicitly. See Conversion From Non-String Types for information on how those data types are converted.

 

Syntax:

string_join_ext(delimiter, values_array, [offset], [length]);

ArgumentTypeDescription
delimiterStringThe string to insert between the values
values_arrayArrayThe array containing the values to join together
offsetRealOPTIONAL The offset, or starting index, in the array to start joining elements. Setting a negative value will count from the end of the array. The starting index will then be array_length(array) + offset. See: Offset And Length
lengthRealOPTIONAL The number of array elements to concatenate, starting at the offset. A negative value will traverse the array backwards (i.e. in descending order of indices, e.g. 2, 1, 0 instead of 2, 3, 4). See: Offset And Length

 

Returns:

String

 

Example 1:

var _words = string_join_ext(" ", ["This", "example", "joins", "words"]);

The above code joins the words in the array into a single string using a space as the delimiter.

 

Example 2:

var _buffer = buffer_create(1, buffer_grow, 1);
var _text_lines = ["This", "file", "will", "have", "multiple", "lines"];
var _file_contents = string_join_ext("\r\n", _text_lines);
buffer_write(_buffer, buffer_text, _file_contents);
buffer_save(_buffer, save_dir + "/" + "text.txt");
buffer_delete(_buffer);

The above code first creates a grow buffer and assigns it to a temporary variable _buffer. It then creates an array with a number of elements and stores that in another variable _text_lines. It then calls string_join_ext on the array with a separator "\r\n", which results in new lines between all the given strings.

It writes the resulting string to the buffer as a buffer_text value and then saves the contents of the buffer to a file named "text.txt" in a directory save_dir. Finally it deletes the buffer to prevent memory leaks.