Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何在字符串中一次循环两行(每次迭代两次回车)?_String_Vb.net_Loops_Split - Fatal编程技术网

String 如何在字符串中一次循环两行(每次迭代两次回车)?

String 如何在字符串中一次循环两行(每次迭代两次回车)?,string,vb.net,loops,split,String,Vb.net,Loops,Split,我想在一个字符串中一次循环两行。我知道我可以通过在回车时使用以下命令拆分字符串中的每一行: For Each line As String In Split(myString, vbCrLf) //do something with line Continue For End If 如何一次遍历两行字符串?我必须使用两个循环吗?你不能使用For..每个循环来完成你要完成的循环,因为循环的定义是通过每个元素循环 您需要使用老式的For循环,该循环带有计数器和步骤指令 Dim stringAr

我想在一个字符串中一次循环两行。我知道我可以通过在回车时使用以下命令拆分字符串中的每一行:

For Each line As String In Split(myString, vbCrLf)
 //do something with line
 Continue For
End If

如何一次遍历两行字符串?我必须使用两个循环吗?

你不能使用
For..每个
循环来完成你要完成的循环,因为循环的定义是通过每个元素循环

您需要使用老式的
For
循环,该循环带有计数器和
步骤
指令

Dim stringArray As String() = Split(myString, vbCrLf)

For loopCounter As Integer = 0 To stringArray.Length - 2 Step 2
    If (loopCounter + 2 >= stringArray.Length) Then
        ' Need to handle the scenario for an Odd number of items in the array
        Debug.WriteLine($"{stringArray(loopCounter)}")
    Else
        Debug.WriteLine($"{stringArray(loopCounter)}:{stringArray(loopCounter + 1)}")
    End If
Next