Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use .Contains(string) with a Select Case Statement?

Tags:

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") 
like image 329
Lou Avatar asked Apr 15 '10 17:04

Lou


People also ask

When should we use Select Case statement write its syntax?

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.

Can we use contains in Switch Case C#?

“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.

What do you mean by Select case?

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.


1 Answers

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 :))

like image 122
AakashM Avatar answered Sep 19 '22 20:09

AakashM