r27371 - New ASH functions: join_strings() is inverse of split_string() by Vera

Veracity

Developer
Staff member
Just as we have:

string[] array = split_string(string input);
=> split input on new-lines and return array

string[] array = split_string(string input, string pattern)
=> split input on pattern and return array

Now we have:

string output = join_strings(string[] array)
=> Join strings in array with new-lines

string output = join_strings(string[] array, string joiner)
=> Join strings in array with chosen separator
 

Veracity

Developer
Staff member
And if your ASH script currently has a main() function with a "string" parameter that you split into keywords to parse:
Code:
void main(string parameters)
{
...
    string[] params = parameters.split_string(" ");

you can use the new "varargs" technique to make the parameters optional and parse them like this:

Code:
void main(string... parameters)
{
...
    // Parameters are optional. Depending on how the script is invoked,
    // there may be a single string with space-separated keywords, or
    // multiple strings. Whichever, turn into an array of keywords.
    string[] params = parameters.join_strings(" ").split_string(" ");
 
Top