0

这是我的工作代码:

Dim commands() =
        {
            "stmotd -a {0}",
            "stmotd -b 15 {0}"
        }


    Dim objLines = File.ReadAllLines("C:\temp\sObj.txt")
    'Dim getcount = objLines.Length

    Using SW As New IO.StreamWriter("c:\temp\MPadd.txt", True)
        For Each line In objLines
            For Each cmd In commands
                SW.WriteLine(String.Format(cmd, line))

            Next
        Next
    End Using

现在“说”我的 sObj.txt 文件包含以下条目“

WINMAC
WINPPC
WINVPN

我用上面的代码得到的输出是:

stmotd -a WINMAC
stmotd -b 15 WINMAC
stmotd -a WINPPC
stmotd -b 15 WINPPC
stmotd -a WINVPN
stmotd -b 15 WINVPN

但我希望输出为:

stmotd -a WINMAC WINPPC WINVPN
stmotd -b 15 WINMAC WINPPC WINVPN

我知道这一定很容易,但我需要一些帮助。谢谢 !

4

1 回答 1

2

尝试:(我现在无法测试代码——这是我的想法)

 Dim commands() =
    {
        "stmotd -a ",
        "stmotd -b 15 "
    }

Dim objLines = File.ReadAllLines("C:\temp\sObj.txt")

 Using SW As New IO.StreamWriter("c:\temp\MPadd.txt", True)
    For Each cmd In commands
        dim com as String=cmd
        For Each line In objLines
            com=com & " " & line
        Next
      SW.WriteLine(com)
    Next
End Using
于 2013-05-21T11:45:03.703 回答