Convert Set to regular String Cell

Hi,

I have a string cell with comma separated items. Some of them are double entries. By using the cell splitter I am able to remove the doubles using the "Output ... as set" option. Ultimately I would like the output as a normal concatenated string. Is there an easy way to convert the set back to a regular concatenated string?

Thanks in advance

Jerry

How about column rename node. Does this allow you to do that

simon.

Hi Jerry,

you can ungroup the set column by using the Ungroup node. Afterwards you can use the GroupBy node with Concatenate as aggregation operation to create the concatenated string.

Bye,

Tobias

 

Thanks to both of you.

I used Simons approach in combination with two string replacer nodes to get rid of the brackets. Ungroup would also multiply all the other columns which is not so convenient for large tables. I still hoped there would be a single node solution. A Java Snippet also came to my mind but I could find a conversion command.

Thanks a lot

Jerry

For the snippet, you could try something like:

String[] r = c_Data;  //(Set this to be your data column)
String t = "";
String delim = ", ";   //Put whatever you want you deliminator to be here!
Boolean isFirst = true;
for (String elem : r){
    t += (isFirst) ? elem : delim + elem;
    isFirst = false;
}

o_Data = t; //(Set this output column to overwrite your data column)

NB - This will say it fails for empty input cells - giving a missing output cell, which is probably fine!

You could take this one step further, and convert your string to a set and then the set to a string all within the snippet!

It works really excellent. This is greatly appreciated.

Thanks a lot

Jerry

I just had the same issue and solved it simply using String.join(delimiter, array) in a “Java Snippet (simple)” node:

return String.join(", ", $timeframe$);
1 Like

There is now a Collection to String node in the Vernalis community contribution which does this with some additional options too.

Steve

2 Likes