How do I turn a string into an array?

Hi all,

I’m a little stuck: I have a string variable which has some data in it which I want to split up as their own values and I don’t know how to do this. Annoyingly, this is the only way to get this information.

So, an EG of the string:

iDealerOptions = Name:Ply Lining Value:£170.00,Name:Bulkhead Value:£200.00
*Note: These names and costs will vary each time but ‘Name:’ and ‘Value:£’ will be consistent.

I want to essentially use ‘Name:’ as a marker and ‘Value’ as another to get the first value (Ply Lining) and then save it as one value, then also get the price for this and have it as another variable, then the same for ‘Bulkhead’ and the price of this also. Perhaps I can somehow put it into a table?

How could I do this? I’m not great with code aha, thanks for your help.

Hi @dr1992

Use the activity text to left/right to get the information you need

This is easy and for the exact same purpose

Cheers

@dr1992
Use below


let me know if you need more explained and optimised one but this will work

First split would be for comma so that we can get n sets of name and value
Then replace and split to get name and value separated for each set , you can then have 2 variable

Hi @dr1992 ,

Here is another solution along with a sequence to help you out:
image

The code is scalable i.e., if there are more line items queued up one after the other, then it will work provided each name, value attributes are separated by a comma.

ConvertStringToTable.xaml (9.4 KB)

Kind Regards,
Ashwin A.K

Hey,

I received a ‘document not valid’ message when opening :frowning:

Hey there,

Thank you for this, but apologies, I’m a bit of a noob aha could you please explain how I’d do this exactly?

HI @dr1992

Please try this activity which is very easy

text to left/right to get the information you need

This is easy and for the exact same purpose

Cheers

Hey Anil,

Apologies, I’m unsure exactly how I would do this and assign each to a variable?

ya


use assign activity
left - create a variable
right - keep the function mentioned in the previous screenshot

HI @dr1992

this is how you do it

image

output
image

str is the variable where the data is stored. You can create a string variable and use it

cheers

1 Like

So would this work even though there are multiple entries within the same string? EG: ply lining is one item and then the Bulkhead is a second?

Hi @dr1992

you can get the second like this

image
image

output:
image

If you dont know how many are there then you can run in loop and give the count to split those many times

cheers

HI @dr1992

Please find the xaml

in this Enumerable.Range(1,2) will give second name and value
similarly change to Enumerable.Range(1,1) will give first name and value
change to Enumerable.Range(1,3) will give the third name and value

and so on

Split.xaml (6.0 KB)

cheers

Hey Anil,

I seem to be getting this when trying to open the xaml

Hi @dr1992

May be it is compatibility issue with our packages

PFB recreate your side in same order

image


1 Like

@dr1992

If you want all the values

Then use like this




cheers