Can we write multiple lines in assign activity

Hi all,

I have assign activity, in that I need to replace string more than 10 times, it makes the assign lengthy and difficult to understand. is there any way we can write multiple rows in assign?

Thanks in advance.
Ulhas

Hi @Ulhas_Guttikar

Check out this thread

Regards

@Ulhas_Guttikar
if you have a complex Assign activity with multiple string replacements, you can make the code more readable by breaking it down into multiple lines using the + operator. Each line should end with Environment.NewLine to represent a new line in the string.

Hi @Ulhas_Guttikar I believe what you would like to have is easier code readabilty. In that case, this might help you…

The actual output will not be in multiple lines. It is just on the code side for easier viewing.

Hi Ave,


I have assign activity like this, If I write these many replace its very hard to read code.

I was curious if there is any way we can write code as shown in SS.
Thanks

You need to add a space character before the underscore. For example:

text.Replace("{-}", Environment.NewLine) _
.Replace("TXNID", "A") _
.Replace("ColumnQ", "B")

Hi Ulhas, I don’t have context of your use case but looking at your screenshot, I believe you can do a direct assign instead of doing replaces:

strComments = vbCrLf & CurrentRow("yourcolumnID").ToString & CurrentRo("yournxtcolumn").ToString....

in such a case we could also model a mini flow, which is config / definition driven and more readable

In UiPath, if you find yourself needing to replace a string multiple times within a single Assign activity, making the expression lengthy and hard to understand, there are several strategies you can employ to simplify the process. While you cannot directly write multiple rows in a single Assign activity for different operations, you can make your workflow more manageable by using one of the following approaches:

  1. Method Chaining

If your replacements are sequential and operate on the same string, you can chain the .Replace() method calls together in one line. This is efficient but can become difficult to read if overused.

myString.Replace(“oldValue1”, “newValue1”).Replace(“oldValue2”, “newValue2”)…and so on

  1. Using a Code Activity

For complex string manipulations, consider using an Invoke Code activity where you can write more complex VB.NET or C# code. This allows you to use loops, conditionals, or even define and call methods to perform your replacements in a more readable and maintainable way.

strVar = strVar.Replace(“oldValue1”, “newValue1”)
strVar = strVar.Replace(“oldValue2”, “newValue2”)

Hi,

Just use

1 “Your data”+Environment.NewLine+
2 “Type other”

image

Just like line by line you can add this and make more multiple rows :slight_smile:

Cheers!!

Hi

This worked for me, thanks for idea.
Cheers.

Hi, Use vbcr
Example var1+vbcr+var2

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