Sunday, 15 July 2012

c# - Streamwriter position seek -



c# - Streamwriter position seek -

this question has reply here:

creating fixed width file in c# 14 answers

i'm trying write text file next data:

texted 00:01:27 8.0 xxxxxxx test texted 00:01:35 251.0 xxxxxxx text

i'm using streamwriter, first building string , writing file:

var v15timestring = item.duration; var v15filestring = " " + item.time + " "; v15sr.write(v15filestring); var durlength = item.duration.length; v15sr.basestream.position = -durlength; v15sr.writeline(item.duration);

the problem i'm having 8.0, 251.0 how write off these. want maintain .0 in lines. in layman terms column should right aligned. i'm refering item.duration in code above.

i did effort above doing streamreader.basestream.position = -durlength, .position doesn't take negative number. how can seek after v15filestring, based on durlength, , write out item.duration

keeping in mind need strictly maintain column left aligned in text file shown in sample above.

kindly help. give thanks you.

you can utilize padleft instead of random spaces

for example

var v15filestring = item.time.tostring().padleft(21); //and v15sr.writeline(item.duration.tostring().padleft(8));

note: ian, has stated, improve build string first, write line

c# .net stream position streamwriter

No comments:

Post a Comment