Showing results for 
Search instead for 
Did you mean: 

Switch Case 'contains'

Add the capability to use 'contains' and not just 'equals' with Switch Case.

Status: Declined

We don't have any plans to change (or add to) the behavior of Switch Case. Switch case is a common programming concept, as as best as we can tell, each branch is always about each Case equaling a value. This type of scenario can already be accomplished today in 2 ways though:


1. You can use nested conditions -- in each condition you can evaluate using whatever expression you'd like.

2. You can use nested if() expressions inside the Switch On.


Personally, I would recommend #2 as that keeps your flow clean - rather than nested conditions which can be difficult to work with. If you had 3 cases it would look something like:



    or(contains(variables('foo'), 'good'), contains(variables('foo'), 'great')),



        contains(variables('foo'), 'bad'),


        if(contains('variables'), 'ok'), 'NeutralCase', 'DefaultCase')




One other thing I'd like to point out is that this approach also gives you much more flexibility than you could ever had if we added contains() to switch case -- for example, you could go down a branch if a string contained one string OR another string.

Super User

Nesting is very nesting intensive and really makes it difficult to setup and bloats the logic.