Multiple Replace

I haven’t been able to find an elegant (non-Python) solution to this one: how can I turn a series of “Replace” nodes (ReplaceByCondition or String.Replace) into something more compact? Basically I have a list of values (in this case a list of 0s,1s and 2s) and need to replace each value with a specific String (0 becomes “Project Base Point”, 1 becomes “Survey Point” and 2 becomes “Relative”). Three keys is manageable, but I’m looking for a solution that works with longer lists of keys. I tried a solution with IndexOf, but that node only seems to pick up the first occurrence of the value. Thanks for any pointers.

Hello Jan,

You can use dictionaries for this, either with code blocks or by using the nodes from Springnodes:

1 Like

Or one (ok, 2!) code block:

This only works as your indexes map directly to the string list. For more complex data structures, @T_Pover example with dictionaries is a good solution

2 Likes

Beautiful! a[x] - couldn’t ask for anything more compact. Thanks much both.