Extracting and Saving Multiple IDs from a Single Cell in UiPath

Hello!

I need some assistance with a UiPath task I’m working on. I have a single cell containing multiple ID/code pairs, separated by newline characters. Here’s an example of the content in the cell:

ID001 - IBUS0301A16
ID001 - IBUS0301A17
ID001 - IBUS0301A18

My goal is to extract each ID/code pair (not the entire pair - e.g. ID001 - IBUS0301A16 only) and save it into a separate variable using UiPath’s Assign activity. Can you provide me with guidance or best practices on how to achieve this? Any help would be greatly appreciated.

Thank you in advance!

Syl

Did you try splitting the text of the cell by Environment.NewLine?

For example:

theTextInYourCell.Split(Environment.NewLine)

Hi @Sylvain_Mazzolini

You can use the below regex expressions to extract the output.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“(^.*)”)

image

Hope it helps!!

Thank you very much for your reply.

I’ve utilized the following Assign command:

arrValue = strInput.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

In the **strInput** variable, I am storing the cell value which includes:
ID001 - IBUS0301A16
ID001 - IBUS0301A17
ID001 - IBUS0301A18

My goal is to use a ‘For Each’ loop for the **arrValue** array. However, I’m unsure about how to assign each “ID/code pair” to a unique variable.

I’m looking to save the string “ID001 - IBUS0301A16” exclusively to the variable ID1.

Following that, I want to store “ID001 - IBUS0301A17” in ID2, and so forth.

I’d greatly appreciate any guidance on how to accomplish this.

Thank you in advance!

Syl

Thank you very much for your reply.

I’ve utilized the following Assign command:

arrValue = strInput.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

In the **strInput** variable, I am storing the cell value which includes:
ID001 - IBUS0301A16
ID001 - IBUS0301A17
ID001 - IBUS0301A18

My goal is to use a ‘For Each’ loop for the **arrValue** array. However, I’m unsure about how to assign each “ID/code pair” to a unique variable.

I’m looking to save the string “ID001 - IBUS0301A16” exclusively to the variable ID1.

Following that, I want to store “ID001 - IBUS0301A17” in ID2, and so forth.

I’d greatly appreciate any guidance on how to accomplish this.

Thank you in advance!

Syl

Hi,

if you’re expecting a fixed number of variables, then you can just keep it simple and use a multi-assign statement instead, in which you can set the variables as:

ID1 = arrValue (0)
ID2 = arrValue (1)
ID3 = arrValue (2)

I don’t see the benefit of using a loop if ultimately you always have a fixed amount of values.
The loop makes sense if you want to make your procedure more dynamic (for example, if the number of values changes, or if you want to apply the same exact behavior in the body of the loop for each value, which is not your case because you’ll have to hard-code the target variable names anyway).

1 Like

Thank you very much!
Syl

1 Like

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