1
我有一個vb.net正則表達式,我正用它來識別簡單的z + x
總和中的運算符。如何使用詞法分析來識別給定表達式中的關鍵字?vb.net在簡單的詞法分析器中識別關鍵字
我當前的代碼:
Dim input As String = txtInput.Text
Dim symbol As String = "([-+*/])"
Dim substrings() As String = Regex.Split(input, symbol)
For Each match As String In substrings
lstOutput.Items.Add(match) '<-- Do I need to add a string here to identify the regular expression?
Next
input: z + x
這就是我想要的輸出
z - keyword
+ - operator
x - keyword
感謝羅賓我也沒有else if語句可用於輸入數字.. –