Domanda

C'è un modo per utilizzare lo statment Select Case in VB.net per beginswith? O devo usare un lungo elseif? Esempio:

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

Ma invece qualcosa come:

Select Case text
Case text.StartsWith("/go")
Case text.StartsWith("/stop")
Case text.StartsWith("/continue")
Case Else
End Select
End Sub
È stato utile?

Soluzione

Si può fare qualcosa di simile

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

Altri suggerimenti

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

Ciò che viene dopo questo comando nella stringa? Se è per esempio uno spazio, è possibile ottenere tutto ciò fino a che lo spazio, e l'uso nella selezione.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top