Splitting a string and performing actions (if statement?)

Hi all,

I have the following value “1 AND 2 AND 3” but for another item it can be “1 AND 2”. I just want to stress that the amount of “AND” values can differ.

I want to perform certain actions if there is 2 times “AND” in the value.
I am trying with split but I’m not managing.

Sequence6 - testing.xaml (7.6 KB)

1 Like

@yannip Change value type from generic to string

Sequence6 - testing.xaml (7.8 KB)

1 Like

Hi @indra, thanks for having a look.

However it does not work as I want. The output of write line var_directive2.ToString is empty and should be “2” and in the if statement i wanted “3” as output and it is giving “none”.

Hi,

You have to split the string with " " value. After this you will have an array with the same positions of AND you have.

Now you have to loop this array for each string of the array, making a counter to count the AND’s

for each String, if String.Contains(“AND”) → counter+1

After that you will know when a String have 1,2,3… AND’s and you will be able to aply your logic

Hope you will understand this. Find this explanation in this .xaml _Test.xaml (10,3 KB)

Kind regards,
Pablo

2 Likes

Hi @yannip

Try this to get count of AND occurrence

Regex.Matches(str,Regex.Escape("AND")).Count.ToString 

Once you get the count you can split the string according to you

Thanks,
Prankur

1 Like

Hi @Pablo_Sanchez,

Brilliant, thanks! Got me in the right direction and found what I was looking for.
Day saver :slight_smile:

1 Like

You are welcome @yannip :slight_smile:

I am really happy to help you and with answers like yours, even more

Kind regards,
Pablo

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