从动态字符串中拆分固定长度的字符串 Vb.net

Splitting strings of fixed length from dynamic string Vb.net

我在 VB 2010 年开发了一个应用程序,其中我通过串行端口向 PLC 发送命令并以字符串形式从 PLC 接收数据。

我已经删除了从 PLC 接收到的不需要的字符串内容,并在 ReturnStr 中得到了最终的字符串,如下所示:

Dim WriteStr, ChkWrite As String
Dim ReadStr, ReturnStr, ChkRecd, ChkCalc As String
Dim ChkComp As Integer

    WriteStr = String.Concat("01", cmd, Add, Points)
    ChkWrite = Check(WriteStr)

    Try
        sp.WriteLine(":" & WriteStr & ChkWrite & vbCr)
        ReadStr = sp.ReadLine()
    Catch ReadErr As Exception
        Return "0"
    End Try

    ChkRecd = ReadStr.Substring((((CInt("&H" & Points)) * 4) + 7), 2)
    ChkCalc = Check(ReadStr.Substring(1, ((Len(ReadStr) - 4))))
    ChkComp = String.Compare(ChkRecd, ChkCalc)

    If ChkComp <> 0 Then
        Return "0"
    End If

    ReturnStr = (ReadStr.Substring(7)).Remove(CInt("&H" & (Points)) * 4)
    Return ReturnStr

ReturnStr returns 类似 006600D000C9006D0013B003A00014C00349 的字符串,我想将其分成 4 个字符的集合。

我的查询是 ReturnStr 可能包含不定长度的数据(4 的倍数)那么我该如何从这样的字符串中拆分字符串并在标签中显示每个子字符串的值格式如下:

lblPt1.Text = CInt("&h" & (ReturnStr.Substring(0, 4)))
lblPt2.Text = CInt("&h" & (ReturnStr.Substring(4, 4)))
lblPt3.Text = CInt("&h" & (ReturnStr.Substring(8, 4)))
lblPt4.Text = CInt("&h" & (ReturnStr.Substring(12, 4)))
lblPt5.Text = CInt("&h" & (ReturnStr.Substring(16, 4)))
lblPt6.Text = CInt("&h" & (ReturnStr.Substring(20, 4)))
lblPt7.Text = CInt("&h" & (ReturnStr.Substring(24, 4)))
lblPt8.Text = CInt("&h" & (ReturnStr.Substring(28, 4)))
Dim s = "006600D000C9006D0013B003A00014C00349"
Dim a = From i In Enumerable.Range(0, s.Length \ 4) Select Mid(s, i * 4, 4)

更新

更新后的问题

Dim labels = { lblPt1, lblPt2, lblPt3, lblPt4, lblPt5, lblPt6, lblPt7, lblPt8 } 
' or query them from Me.Controls.OfType(Of Label) or just use ListBox or better conrol
ReturnStr = ReturnStr.PadRight(labels.Length * 4)

For i = 0 To labels.Length - 1
    labels(i).Text = Val("&h" & Mid(ReturnStr, i * 4, 4))
Next