我正在嘗試從sObj.txt中讀取文本&在MPadd.txt中寫入一些前綴文本。 sObj.txt包含一個垂直的單詞條(每行1個)&該文件中的行數是可變的(由用戶決定)。下面是我使用的腳本:獲取錯誤IndexOutOfRangeException未處理
Dim commands() =
{
"stmotd -a {0}",
"stmotd -b 15 {0}"
}
Dim counter As Integer = 1
Dim objLines = File.ReadAllLines("C:\temp\sObj.txt")
Using SW As New IO.StreamWriter("c:\temp\MPadd.txt", True)
For Each line in objLines
SW.WriteLine(string.Format(commands(counter), line))
counter += 1
Next
End Using
但在執行時會返回錯誤「IndexOutOfRangeException是未處理」還表示,指數數組的邊界之外。請幫忙。
你的代碼工作,但輸出是 stmotd -a WINFPH stmotd -b 15 WINFPH stmotd -a WINMAC stmotd -b 15 WINMAC stmotd -a WINPPC stmotd -b 15 WINPPC stmotd -a WINVPN stmotd -b 15 WINVPN 其中WINxxx是來自sObj.txt文件的文本。 不過,我需要這樣的輸出: stmotd -a WINFPH WINMAC WINPPC WINVPN stmotd -b 15 WINFPH WINMAC WINPPC WINVPN 能否請你幫忙嗎? – slyclam
@slyclam請參閱編輯。 – GSerg