我想从文本框中计算空间,数组应该在那里,其长度应该等于空格数并将每个单词存储到数组
答案 0 :(得分:1)
Dim words() As String = Textbox.Text.Split()
如果您因任何原因需要检查每个单词:
For a = 0 To words.Length - 1
' do your stuff here
Next
答案 1 :(得分:0)
使用Regular Explessions并将结果转换为字符串数组。
Dim matches() As String = Regex.Matches("Your string for testing", "\S+") _
.OfType(Of Match)() _
.Select(Function(m As Match) m.Value) _
.ToArray()
' matches(0) is "Your"
' matches(1) is "string"
' matches(2) is "for"
' matches(3) is "testing"
要重复matches
集合中每个元素的任何操作,请使用For-Each循环:
For Each match As String In matches
' Do something with match variable
Next
要使用Regex
类,您需要导入System.Text.RegularExpressions
命名空间。