我有vb的问题。我不能这样做
For Each Letter As Char In TextBox1.Text
Select Case TextBox1.Text
Case "run"
'Code
Case "ok"
'Code
End Select
Next
所以它的作用是重复单词中的字符数量我只想让它做一次
我有vb的问题。我不能这样做
For Each Letter As Char In TextBox1.Text
Select Case TextBox1.Text
Case "run"
'Code
Case "ok"
'Code
End Select
Next
所以它的作用是重复单词中的字符数量我只想让它做一次
您需要将TextBox1.Text
内容拆分为单词,然后遍历单词:
For Each word As String In TextBox1.Text.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)
Select Case word
Case "run"
'Code
Case "ok"
'Code
End Select
Next
使用空格作为分隔符将文本解析为单词数组。然后,您可以使用 for 循环和您的 Case 语句。
Dim i As Integer
Dim aryText() As String
'SPLIT THE TEXT INTO AN ARRAY'
aryText = TextBox1.Text.Split(" "c )
For i = 0 To UBound(aryText)
Select Case aryText(i)
Case "run"
'Code
Case "ok"
'Code
End Select
Next