How to extract specific part from a string using specific separator and add those string in an array/collection and loop through it

Hi Team,

I have a string like this :- ‘18-25’!C11 + ‘18-25’!C57 - ‘18-25’!C86
The specific part of the string is separated by + or - … Here we can have any number of separators here which is + or -.

I have to extract the string on the basis or + or - and add that part in an array and collection and will loop through array
for ex:- for string ‘18-25’!C11+‘18-25’!C57-‘18-25’!C86
I get 3 extracted strings which is :- ‘18-25’!C11 , ‘18-25’!C57 and 18-25’!C86

Now I have to add these strings in an array or collection.so that the first item will be to loop through is ‘18-25’!C11 , second will be ‘18-25’!C57 and the third will be 18-25’!C86.
Here the main string will be of any length, here in this case I get 3 sub - strings but it can be more also.

Please help

Would the + or - you want to split the string on, always be before a single quote ( ’ )?

Hi ,

Can you try using these statements in Assign activity

Str var = “‘18-25’!C11+‘18-25’!C57-‘18-25’!C86”
Array = str.Split(new String(){"+’","-’"}, StringSplitOptions.None)

I want to split on the basis on of + or - not necessary that it will be before (’)

In your sample string: ‘18-25’!C11+‘18-25’!C57-‘18-25’!C86, how would you differentiate between the ‘-’ in ‘18-25’ and ‘C57-‘18’ ?

Hi , I have implemented it . It is not giving me the desired result

Please change that Quotes . The Copy paste may be different.
Also share the output you are getting.

Yes I noticed the same too, this is the challenge here

@Karan28
as an alternate you can give a try to RegEx:
grafik
‘\d+[-,+]{1}\d+’![A-Z,\d]+

grafik

find starter help here:
Sequence2.xaml (5.6 KB)

Thankyou so much for this solution

Hey I have checked it and its working absolutely fine , but in my case the main string can change a little bit so if you can give me solution on that then it will be a dynamic solution for me.
Like my string can be like this too :- schedule!C11+CFS!C57-karan!C86+verse!C86
I mean the say the string before “!” can change which is schedule in this case schedule!C11
and was ‘18-25’ in earlier case - ‘18-25’!C11+‘18-25’!C57-‘18-25’!C86

your solution works absolutely fine in this case but can you make it more dynamic s0 that it should work in second case too

maybe following will work

(+|-)?([A-Z,a-z,\d,’,-]+![A-Z\d]+)

you will refer to group 2
grafik

for working with groups have a look here:

1 Like

Hey I am getting this error for this ,
Screenshot (87)

@Karan28
It passed the tests at my end. Have a look here:
Karan_TestMatches.xaml (6.5 KB)

grafik

Hey , This solution works and this solution is so magnificent and you are so technically strong man. Bravo!!

1 Like

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