Switch statement - contains

Hi,

I’m trying to do the following:

I have a switch and some situations where I should be able to evaluate whether a variable contains a certain value. However, I get an error when I add the “contains” syntax: Overload resolution failed because no accessible “contains” accepts this numer of arguments.

image

How can I still achieve this within my switch activity?

@yannip In Switch properties Change TypeArgument to string

Hi indra,

it is already string :).

.Contains function takes a string argument. I believe that would be the change you have to do .
Thanks.

1 Like

If you want to use contains you will have to change the whole condition to add outputs and then check the outputs.
Like Uthraa said contains takes a argument varPO_Sector1.ToString.Contains(“Machinery”) for example

See the below if this helps as it fits your use-case :slight_smile:

3 Likes

Ok thanks, i just included another if to solve it eventually… :slight_smile:

Another question, rather simple but I am not getting my result.

I want to split the following to get the value (PPER) between the second brackets:
Machinery (CPR) AND Destruction (PPER)

I was trying the following string.split(“AND"c)(1).split(”)“c)(0).split(”("c)(1) but i think i have an issue when splitting on “and”?

1 Like

Why so complicated.
Also split take only a char not a whole AND :slight_smile: may be thats the error reason

You can simply do string.Subtring(string.LastIndexOf("("),4) and you will get PPER

1 Like

Thanks, because sometimes I have “AND” three times and I need the value after the first “AND” and the characters between brackets can be 3 or 4 or 5 or even 10.

Give me a example, ill provide you the string function

Example 1: Machinery (CPR) AND Destruction (PPER)
Example 2: Testing (ABCDEF) AND Machinery (MACHINEPOLLUTION) AND Abuse (POSL)

For example, I need some code that would give me PPER in the first case and MACHINEPOLLUTION in the second case.

I had to come back to your logic to do it in one statement. :slight_smile:

output = string.Split({"AND"},StringSplitOptions.RemoveEmptyEntries)(1).Split("("c)(1).Replace(")","")

1 Like

Thank you, looks very neat :).

1 Like

Hi @nadim.warsi,

Another “split” question. I need to split the following “2010 - trmlo202010 - 21 - 23” and the output should be “trmlo202010 - 21 - 23”. If i split on “-” with index 1, I only get the ‘trmlo202010’ part. Also it is variable, I know there will be at least 1 “-” and I need to get the string after this first “-”.

yes in this case you go with sub-string and not split
string.Substring("-").Trim

This will give you string after 1st ‘-’

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