通过新行字符使用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