通過新行字符使用TextBox
的Lines
值,而不是分裂的,就像這樣:
Dim lines() As String
lines = TextBox1.Lines
現在,你可以通過字符串數組循環,讓每個字符串的第一個字符,像這樣:
For Each line As String In lines
' Protect against strings that do not have a first letter to check
If line.Length >= 1 Then
Dim firstLetter As Char
firstLetter = line.Substring(0, 1)
End If
Next
然後你就可以把邏輯來檢查的第一個字母是一定值,就像這樣:
If firstLetter = "[" Then
MessageBox.Show("I found it!")
End If
注:以上我概述了隔離措施,但很明顯,你可以結合一些這些東西一起爲更簡潔的解決方案,如:
For Each line As String In TextBox1.Lines
' Protect against strings that do not have a first letter to check
If line.Length >= 1 Then
Dim firstLetter As Char = line.Substring(0, 1)
If firstLetter = "[" Then
MessageBox.Show("I found it!")
End If
End If
Next
我們可以看到你輸入的數據? – MichaelEvanchik
他們是「」的原因是因爲你需要檢查http://msdn.microsoft.com/en-us/library/system.stringsplitoptions(v=vs.110).aspx,但也使用不同的方法,如其他答案指出。 – JDwyer