Public Sub Main(temp As String)
Dim AccNo As String = temp.Substring(0, 18)
Dim Identifier As String = temp.Substring(36, 46)
Dim Expected As String = temp.Substring(45, 98)
Dim Received As String = temp.Substring(100, 105)
Dim Length As String = temp.Length.ToString
lbLength.Text = Length.ToString
lbAcc.Text = AccNo.ToString
lbIdentifier.Text = Identifier.ToString
lbExpected.Text = Expected.ToString
lbReceived.Text = Received.ToString
End Sub
我正在尝试从字符串行中提取一个部分。它先正常工作两次,然后生成
索引和长度必须引用字符串中的位置。”&vbCrLf&“参数名称:length vb.net”
请帮助我解决这个问题。
答案 0 :(得分:0)
Substring(StartPosition,length)长度是从起始位置开始的字符数。
如果您想像Substring(start_position,end_position)那样将结束位置替换为(98-45),因为end-start = length
答案 1 :(得分:0)
在Sub的开头检查临时字符串的长度。
Dim temp As String = ""
If temp.Length < 205 Then
MessageBox.Show("String is too short to process")
Exit Sub
End If