Split a value in an array and make a new array


I'm pretty new to crystal. I have a parameter called {?names} which allows multiple values that will search the database for all those names or something similar. I want to check every value of the array for a "," just in case somebody writes "last name, first name". If it does contain "," then I want to split it at the "," and then make a new array where all the values are their own value in the array. Like this:

    {?names} = ["hank", "jerry", "smith, john", "peterson"]

How would I check every value of the array for a "," and if it is found, split it and separate it into two different values in a new array? Like this:

    new {?names} = ["hank", "jerry", "smith", "john", "peterson"]

Sorry if this is a noob question, but I kinda am a noob. Thanks for your help!

Best Solution

Create a formula field:

Stringvar Array names := Split( Join({?Names},","), "," );

// test the results or do whatever
Join(names, ":")

This approach won't remove spaces, however. "smith, john" will result in "smith", " john", for example.

It that is important, try this approach:

Stringvar Array names:= Split(Join({?Names},","),",");

Stringvar Array output;
Redim output[ubound(names)];

Local Numbervar i;

for i:=1 to ubound(names) do (

    output[i] := trim(names[i]);