I have a text stream data like :
<dimension>{{count}}</dimension>
<v>1</v>
<v>2</v>
<v>3</v>
....
<v>100000</v>
I use streamwriter to write data into a file (because I want to avoid OOM situation) and only after wrting all data then I colud know the dimension
count.
So I'd like to replace {{count}}
mark by the count after writing.
Steps logic like:
var count = 0 ;
using (var stream = File.Create(path))
using (var writer = new StreamWriter(stream))
using (var reader = GetReader())
{
while(reader.Read())
count++;
writer.Write(reader.GetValue());
}
//Go to file top and edit/update/replace `{{count}}`
stream.TopReplace("{{count}}",count);
}
I've read :
- string - C# Read text file line by line and edit specific line - Stack Overflow
- c# - XmlReader - I need to edit an element and produce a new one - Stack Overflow
so right now my way is read all data into memory
then edit on it, but it loss streamwriter point...