在VB.Net中对str strwords进行排序

在VB.Net中对str strwords进行排序,vb.net,Vb.net,我能把代码缩短一点吗?我不想写太多次,所以我想把它缩短。仅针对前5行,我不想针对文本框的所有行 str2 = TxtBoxIntDraws1.Lines(0) Dim strWords2 As String() = str2.Split(",") str3 = TxtBoxIntDraws1.Lines(1) Dim strWords3 As String() = str3.Split(",") str4 = TxtBoxIntDraws1.Lines(2) Dim strWords4 As S

我能把代码缩短一点吗?我不想写太多次,所以我想把它缩短。仅针对前5行,我不想针对文本框的所有行

str2 = TxtBoxIntDraws1.Lines(0)
Dim strWords2 As String() = str2.Split(",")
str3 = TxtBoxIntDraws1.Lines(1)
Dim strWords3 As String() = str3.Split(",")
str4 = TxtBoxIntDraws1.Lines(2)
Dim strWords4 As String() = str4.Split(",")
str5 = TxtBoxIntDraws1.Lines(3)
Dim strWords5 As String() = str5.Split(",")
str6 = TxtBoxIntDraws1.Lines(4)
Dim strWords6 As String() = str6.Split(",")     

你可以像下面这样做

For idx = 0 To 4
    str = TxtBoxIntDraws1.Lines(idx)
    Dim strWords As String() = str.Split(",")
Next idx
如果希望以后处理拆分的字,可以将数据保存到数组中,然后再进行处理。 为此,请遵循以下代码

Dim idx As Integer
Dim strWords(5)() As String
For idx = 0 To 4
    str = TxtBoxIntDraws1.Lines(idx)
    strWords(idx) = str.Split(",")
Next idx

' process strWords

对Vignesh Kumar A的回答进行改写。这将给出第1-4行。指数从零开始

Private Sub OPCode()
    Dim blankList As New List(Of String())
    For i = 0 To 3
        blankList.Add(TextBox1.Lines(i).Split(","c))
    Next
End Sub

很好的尝试,但不幸的是,每次迭代都会覆盖strWords,结果只会是第五行的最后一部分。@Mary,我已经更新了答案。顺便说一下,谢谢。