Separate Text Easy method

Hi Guys, Merry Christmas to all,

Hoping someone could suggest a simplified way of executing what I am trying to achieve.

I have a body of text eg:

Linked Accounts - BF_123456, PP_123456 | Retail Accounts - None
12/08/1991 - - X X on brand

What I am trying to grab is the BF_123456, and PP_123456, and just the numbers at that.
The main concern is that there could be one, or there could be three eg: just BF_123456 | Retail etc but there could be more.

Many Thanks

1 Like

Hi
We can use this expression in MATCHES activity
“(_)(\d)+”
Then get the output from. MATCHES activity and pass that as input to FOR EACH activity and change the type argument as System.Text.RegularExpressions.Match

—inside the loop use a writeline activity and mention like this
item.ToString.Replace(“_”,””).Trim

Cheers @Kyleb91

Thanks @Palaniyappan but I’m not familiar with Matches, I presume the Test Text is the variable of text, and then use Starts With BF/PP?

I didn’t get this buddy

Do you mean like it’s in a txt file
Cheers @Kyleb91

Sorry I understand how to use the activity now… the output is however giving me _12346 instead of just 123456…?

1 Like

That’s why buddy we can use Replace method to remove that _

Also, would there be a way of getting each match of “PP_” OR “BF_”?

To get only BF_
Then the expression be like this
(BF_)(\d)+
And I see the loop use a REPLACE method like this
item.ToString.Replace(“BF_”,””)

Similarly for PP_
the expression be like this
(PP_)(\d)+
And I see the loop use a REPLACE method like this
item.ToString.Replace(“PP_”,””)

cheers @Kyleb91

1 Like

Hi Mate, thanks again for all the help, wondering if you could help me with developing my solution here, finding many difficulties getting this to work.

Above I want to get all ID’s but separated by BF, or PP.

If let’s say, there is Linked Accounts - BF_123456, BF_7890, PP_123456 |

If the IDs are BF starting, I want to get the BF ID’s in a ‘123456, 7890’ format, so I can input into a data script to run. But the script will be specific for BF IDs only.

Then I would like to store the PP ID in the else part of an IF statement, so be able to have them separated in 12345, 12345 format (potentially there would be more than one, but maybe none at all). These will then be run in a different script, these PP IDs will then have to be run in one of two scripts, which is determined by the date of the account (before 2016) but I can run all PP IDs in both scripts regardless to see if any output and append to sheets accordingly, so not too worried about that.

Does this make sense? Any way you could help?

Many Thanks :smiley:

yah of course
before proceeding to take the values with either BF or PP we can check with the string like which format it has using a IF condition like this
str_input.ToString.Contains(“PP_”)
IF true it will go to THEN part where we can place the set of activities that will take the value from PP_ and then proceed further with the remaining activities
OR
if that fails it will go to ELSE part where we can place the set of activities that will take the valur from BF_ and then proceed further with the remaining activities

Cheers @Kyleb91

Yes this makes sense, but I want to store all values - and there can be BF_ AND PP_ in some cases…

Fine
in that case first let us confirm whether it has both with a IF condition like this
str_input.ToString.Contains(“BF_”) AND str_input.ToString.Contains(“PP_”)
IF true it will go to THEN part where
–first use a assign activity like this
bool_both = True
where bool_both is a variable of type boolean defined in the variable panel with default value as False

then we can use MATCHES activity with this expression
“(_)(\d)+” and Then get the output from. MATCHES activity and pass that as input to FOR EACH activity and change the type argument as System.Text.RegularExpressions.Match

—inside the loop use a writeline activity and mention like this
item.ToString.Replace(“_”,””).Trim

now next to this IF condition use this as mention

but with a additional condition like this
str_input.ToString.Contains(“PP_”) and bool_both = False

Cheers @Kyleb91

Hi man - I think the above is a bit too complicated - I seem to have got what I need with the below:

image

Here I have got the Id’s in a for each - and then assigning with BFID +", " + BFID.ToString, because I want to get the IDs then in the format “123456, 789012” but I keep getting them like “123456, 123456” and then “789012, 789012”, which makes sense as it is doing it ‘FOR EACH’ but is there a way of simply combining these for each’s to one string of “123456, 789012”?

Thanks

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