Question

Est-il possible d'utiliser le statment Select Case dans VB.net pour beginswith? Ou dois-je utiliser une longue elseif? Exemple:

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

Mais au lieu quelque chose comme:

Select Case text
Case text.StartsWith("/go")
Case text.StartsWith("/stop")
Case text.StartsWith("/continue")
Case Else
End Select
End Sub
Était-ce utile?

La solution

Vous pouvez faire quelque chose comme

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

Autres conseils

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

Ce qui vient après cette commande dans la chaîne? S'il est par exemple un espace, vous pouvez obtenir tout à cet espace, et l'utilisation dans la sélection.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top