views:

57

answers:

3

Is there a way to use the Select Case statment in VB.net for beginswith? Or do i have to use a long elseif? Example:

If text.StartsWith("/go") then
elseif test.StartsWith("/stop")
elseif test.StartsWith("/continue")
End If

But instead something like:

Select Case text
Case text.StartsWith("/go")
Case text.StartsWith("/stop")
Case text.StartsWith("/continue")
Case Else
End Select
End Sub
A: 

What comes after this command in the string? If it is for example a space, you can get everything up to that space, and use in the select.

Guffa
+2  A: 
Select Case True
 Case text.startswith("/go") :  messagebox.show("Go")
 Case text.startswith("/stop") :   messagebox.show("stop")
 Case text.startswith("/continue") :   messagebox.show("continue")
End Select
Kamyar
I picked the other person because 1. He answered first and 2. His is easier to read.
Bubby4j
@Bubby: No problem. Glad you got your answer anyway.
Kamyar
+1  A: 

You can do something like

Select Case True
    Case text.StartsWith("/go")
        ...
    Case text.StartsWith("/stop")
        ...
    Case Else
End Select
cHao