Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1050
  • Last Modified:

StartsWith Select Case

Is there a slick way to use the StartsWith in combination with a Select/Case? Something like this (which doesn't compile):

        Select Case TextBox1.Text.ToUpper
            Case String.StartsWith("AB")
            ' ...
        End Select

Instead of a bunch of:

 If TextBox1.Text.ToUpper.StartsWith("AB") Then
 ElseIf ..  ("CD")

and so on.
0
GivenRandy
Asked:
GivenRandy
2 Solutions
 
AlexFMCommented:
No, Case allows only constants. Do this with If - ElseIf - Else operator.
0
 
super786Commented:
If you can define the length of your search string (ie, 2 characters) then you can do:

Select Case TextBox1.Text.SubString(0, 2).ToUpper()
   Case "AB"
   Case "CD"
   Case "EF"
end select

but if you have a variable length search string, then you can't do it unless you can specify a delimiter or something.  Ie, all strings start with the code string followed by a colon (:).  Then you can pull the string up to the colon before you run it through the select case.
0
 
GivenRandyAuthor Commented:
That's the way I had done it. Didn't know if they was some Framework trick I was missing (the thing is massive).
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now