streamwriter for txt output file

oren tu

New member
Joined
Nov 6, 2019
Messages
2
Programming Experience
5-10
hi all

im using streamwriter to output to text file fixed length

i have:

L="{0,-7}{1,-10}"

and the text with spaces

R="12345 1234567 "

when i run

streamwriter.writeline (L,R)

i get error INDEX ZERO MUST BE GREATER....ERROR

but when i run just block is ok

L="{0,-7}"

and the text with spaces

R="12345 "
 
Take a look at the WriteLine() call, it's overloaded and you're using one of the overloads but aren't meeting the index criteria for it.
Of course I know what you're trying to do with your code and what you're needing to do is concatenate your variables when you call WriteLine()
 
Your format string "{0,-7}{1,-10}" says that you have two items to be formatted. You are only passing one item to be formatted when you call WriteLine():
C#:
WriteLine(
    "{0,-7}{1,-10}",    // format string
    "12345 1234567 "    // first item to be formatted
                        // where is the second item to be formatted?
    );
 
Back
Top Bottom