You need to use an IF
statement to preform the kind of check you want.
You have two options StartsWith
and Contains
.
StartsWith
will allow you to check if your keywords are at the start of the string.
- Eat Banana = True
- Banana Eat = False
Contains
will allow you to check if your keyword exits anywhere.
- Eat Banana = True
- Banana Eat = True
StartsWith Example
Private Sub AllocateType(ByVal Command As String)
If Command.StartsWith("Eat") Then
'Call Eat procedure
Else If Command.StartsWith("Use") Then
'Call Use procedure
Else If Command.StartsWith("Quit") Then
'Call Quit procedure
Else If Command.StartsWith("Pause") Then
'Call Pause procedure
Else If Command.StartsWith("Go") Then
'Call Go procedure
Else
Errors()
End If
End Sub
Contains Example
Private Sub AllocateType(ByVal Command As String)
If Command.Contains("Eat") Then
'Call Eat procedure
Else If Command.Contains("Use") Then
'Call Use procedure
Else If Command.Contains("Quit") Then
'Call Quit procedure
Else If Command.Contains("Pause") Then
'Call Pause procedure
Else If Command.Contains("Go") Then
'Call Go procedure
Else
Errors()
End If
End Sub
Also with StartsWith
or Contains
you can do StringComparison
this will allow you to ignore case.
If Command.StartsWith("Eat", StringComparison.OrdinalIgnoreCase) Then
OR
If Command.Contains("Eat", StringComparison.OrdinalIgnoreCase) Then
Ignoring the case will match "EAT", "Eat", "eAt", etc.