Get value and alias of selected values from a list

If you have a list of choices (called Choices), say ”one|1” : ”two|2” : ”three|3” : ”four|4”, and have ”1” : ”3” as the selected (called Selected), how do you get the corresponding values ”one|1” : ”three|3” (called Result)? I thought it would be simple, like:

@Left(Choices; "|" + Selected) + "|" + Selected 

…but @Left doesn’t work with two lists, only one. So I had to loop through the lists instead, with the code below. It is quite useful when populating checkboxes and multi-value select boxes.

Choices:="one|1" : "two|2" : "three|3" : "four|4"; Selected:="1" : "3"; allOptions:=@Right(Choices; "|"); @For(n:=1; n <= @Elements(allOptions); n:=n+1; 	en:=@Subset(@Subset(allOptions; n); -1); 	@For(m:=1; m <= @Elements(Selected); m:=m+1; 		em:=@Subset(@Subset(Selected; m	); -1); 		Result:=Result : @If( 			en=em; @Subset(@Subset(Choices; @Member(em; allOptions)); -1); 			"" 		) 	) ); @Trim(Result); 

The code above works only in R6+, since it involves loops. If any of you could figure out a way of doing this in R5, let me know!I helped a collegue of mine, that wanted the same functionality in R5, and come up with the following simple formula, that also works in R6, make sure that your aliases are strictly unique (1 and 11 is not unique in this formula, but 01 and 10 are):

@Trim(@Left(@ReplaceSubString(Choices; Selected; "$$$$"); "|$$$$"))