针对2个数组的VB.NET Run命令

时间:2015-06-25 09:20:59

标签: arrays vb.net string join text

我已经将2个文本文件读入2个数组,只想运行使用2个数组的命令。

示例:

part1.txt(array 1)
hxxp://somethinghere.com\1
hxxp://somethinghere.com\2

part2.txt(array 2)
Bob
James


myprogram.exe hxxp://somethinghere.com\1 Bob
myprogram.exe hxxp://somethinghere.com\2 James

我只是想运行一个遍历两个数组的for循环,这是我到目前为止所拥有的:

Dim part1() As String = IO.File.ReadAllLines("C:\part1.txt")
Dim part2() As String = IO.File.ReadAllLines("C:\part2.txt")

For Each line As String In part1
    MsgBox(line)
Next

编辑: 工作代码:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim part1() As String = IO.File.ReadAllLines("C:\part1.txt")
    Dim part2() As String = IO.File.ReadAllLines("C:\part2.txt")

    For parse As Integer = 0 To part1.GetUpperBound(0)
        MsgBox(String.Concat("myprog.exe " & """" & part1(parse) & """" & " -arg1 " & """" & part2(parse) & ".txt" & """"))
    Next
End Sub

所以它看起来像这样:

myprog.exe" hxxp://somethinghere.com" -arg1" Bob.txt"

3 个答案:

答案 0 :(得分:0)

看看Enumerable.Zip

  

Enumerable.Zip(Of TFirst,TSecond,TResult)方法

     

将指定的函数应用于两个序列的相应元素,生成一系列结果。

所以你可以像

那样
Dim part1() As String = IO.File.ReadAllLines("C:\part1.txt")
Dim part2() As String = IO.File.ReadAllLines("C:\part2.txt")

For Each element In part1.Zip(part2, Function(a, b) New With {a, b})
    MsgBox(String.Format("{0} - {1}", element.a, element.b))
Next

答案 1 :(得分:0)

这样的事情怎么样?

 Private Sub testMethod()

        Dim part1() As String = New String() {"one", "two", "three"}
        Dim part2() As String = New String() {"10", "20", "30"}

        For parse As Integer = 0 To part1.GetUpperBound(0)
            Debug.Print(String.Concat("command ", part1(parse), part2(parse)))
        Next
    End Sub

答案 2 :(得分:0)

首先检查数组的长度是否相同,然后你可以循环一个数组的索引并访问另一个数组中的相应项。

要运行程序,您可以使用$jsonstr = '[{"customerId":"1","customer_name":"Jon_doe","amount":"12312312","billcode":"b1231","billname":"cashbilname","billcategorycode":"1234","billcategory":"utility","month":"May","year":"2015","txcode":"10","stationid":"152","station":"Coroom","operatorcode":"1200","operator":"jame","terminal":"ter12312","txdate":"12\/2\/2015","txtime":"12:21:22_PM"}]'; $ar = json_decode($jsonstr,true); # json string to Array $obj = json_decode($jsonstr); # json string to Object var_dump($ar,$obj); 对象指定参数:

ProcessStartInfo

您可以在Dim part1() As String = IO.File.ReadAllLines("C:\part1.txt") Dim part2() As String = IO.File.ReadAllLines("C:\part2.txt") If part1.Length = part2.Length Then For i As Integer = 0 To part1.Length - 1 Dim p As New ProcessStartInfo p.FileName = "myprog.exe"; p.Arguments = """" & part1(i) & """ -arg1 """ & part2(i) & ".txt""" Process.Start(p); Next Else ' Oops! different number of items in the files ' Tell the user End If 对象中设置更多属性,以控制程序的启动方式。