Splitting a Variable in two and Assigning them each to a new variable

I’ve got a code where it pulls a UI element, and then splits it in two at the “-” in the text pulled. I cannot figure out how to then assign each of the elements of the array to a new variable. The variable being split I have saved as an array of string.

I have used assign,

DepDate = Dep.Split({“-”},stringsplitoptions.None)

and when I use a for each and message boxes shows me that it has successfully split the original variable. Now, how do I assign each of those to their own new variable?

I’ve tried an assign, but I don’t know the correct syntax to select the part of the array.

Assign,

DepDate(0) = NewVariable

gives me a blank box with nothing in it when displayed as a message box.

2 Likes

You were so close! You just needed the (#) at the end.

Try this (but in an assign stage):

2019-08-29%2011_38_33-UiPath%20Studio%20-%20BlankProcess

2 Likes

So, I did that, but now I get the following issue when assigning the variable for each.

I’ve got the two you suggested above in two assign boxes, and then the following in an assign box

Depdate = Newvar1

and

Depdate = Newvar2

These give me the following error

“Option Strict On disallows implicit conversions from ‘String’ to ‘Char’”

All variables are set as strings though.

When I attach message boxs directly to the output of the split with (0) and (1) on the end like you suggested, the split is then broken and only displays the first letter of the UI element.

What is the string you are trying to split? Can you share it?

1 Like

The string changes based off of what is grabbed from the UI element but it is always of the format,

“Word - JAN 2021”

Where the last four digits and three letter month abbreviation change. The split I used works perfectly to split at the “-” the issue is the assiging it to two separate variables.

Are you able to post a screenshot of your variables pane?

Try this. Here “arr” is array of string.

This is what I have now. With the string as (0) and (1) on the end as you suggested.

1 Like

I think you may have your expressions backwards.

It should be like this in your assign stage:

ManDate = Deploy.Split({“-”},stringsplitoptions.None)(0)
ManEvent = Deploy.Split({“-”},stringsplitoptions.None)(1)

Edit: My apologies, I didn’t read the entire flow. But the split function should be used on your original string value that contains the dash.

Wow, that was my only issue was flipping the two in the assign box. Solved all my issues. I was so close yet so far.

1 Like

That’s great news!

Next time you need to do this it’ll only take a few seconds, first time is always the hardest :slight_smile:

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