vb.net - Getting error IndexOutOfRangeException was unhandled -
i trying read text sobj.txt & write in mpadd.txt prefix text. sobj.txt contains vertical strip of words (1 in each line) & number of lines in file variable (determined user). here script using:
dim commands() = { "stmotd -a {0}", "stmotd -b 15 {0}" } dim counter integer = 1 dim objlines = file.readalllines("c:\temp\sobj.txt") using sw new io.streamwriter("c:\temp\mpadd.txt", true) each line in objlines sw.writeline(string.format(commands(counter), line)) counter += 1 next end using
but when executed returns error "indexoutofrangeexception unhandled" says index outside bounds of array. please help.
arrays in .net zero-based.
use
dim counter integer = 0
and obviously, objlines
may contain no more 2 lines.
maybe meant emit commands
each line?
for each line in objlines each cmd in commands sw.writeline(string.format(cmd, line)) next next
edit:
dim joined_lines = file.readalltext("c:\temp\sobj.txt").replace(vbnewline, " ") using sw new io.streamwriter("c:\temp\mpadd.txt", true) each cmd in commands sw.writeline(string.format(cmd, joined_lines)) next end using
Comments
Post a Comment