Modify each String in a list of String?

Hi everyone.

I’ve got a list of strings, and I want to apply Replace and Trim on each String in that list. Here’s my attempt:

The problem for this is that the recapslist remains unchanged. It seems that “item” is only a copy of the list item, not the actual list item being modified.

I’ve tried this but it doesn’t work:

Any ideas? Thanks in advance.

give a try on following

Assign Activity
LHS: RecapsListCleansed | datatype: List(Of String)
RHS:
e.g.
RecapsList.Select(Function (x) x.Replace(Environment.Newline,“”).Replace(" “,”").Trim).toList

Kindly note: Your " " replace (refering to your screenshot) is replacing again with a blank

3 Likes

This should work:

RecapsList = RecapsList.select(function(x) x.replace(" ", " ").trim)).toList
1 Like

Hi @matteo.tatibouet,

in the above sequence you are trying to modify the item field but not appending or adding it to another list. That is the reason it is remaining unchanged.

Please create a new list and after performing replace operation, add the updated string to the new list and use the updated list going forward.

Hope this helps. Let me know if you face any issues.

1 Like

Thank you all for your help, indeed the easiest way to solve this problem is to make a second list that gets added each item in the for each loop. For those who wonder, it is not possible to change the value of a list item.

Did you try my solution? It would probably be much more efficient than creating a second list and looping through everything. Especially if the size of the list is large.

1 Like

Hey Greg, I couldn’t get your solution to work right now so I went with the second list method, If my robot ever needs upgrading I’ll probably make your solution work. Thanks again!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.