Is there anyway I can build a Select statement that uses the Contains function? Like this:
Select commentStr Case commentStr.Contains("10") Case commentStr.Contains("15")
A Select Case statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each select case.
“switch case c# contains” Code Answer Correct final syntax for [Mr. C]s answer. You should take care of the case ordering as the first match will be picked. That's why "test2" is placed prior to test.
Select Case is a conditional statement, that helps you test a variable for equality against a set of values. Each value is referred to as a case, and a variable that is being switched on should be checked for all the select cases.
Select Case True Case commentStr.Contains("10") 'foo Case commentStr.Contains("15") 'bar End Select
Note that with this construct, a maximum of one Case
will be executed.
(Also note that your C# friends can't do this with switch
, which requires constant expressions in the case
clauses :))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With