By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,420 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,420 IT Pros & Developers. It's quick & easy.

Writing to a particular position

P: n/a
Hello;
I have a text file. Assume that this file has some textual content. I
want to append a text into this file at a specific position; not to the
end of file. I assume that one way of doing this would be setting the
stream length, shifting the characters after the position + lengt to
the end, but this method seems inefficient to me. Another way might be,
storing the text content in an array and manipulating and writing this
array to the file, but this seems inefficient to me too.
Is there any way of doing this without the methods i thought about
above ? All ideas are appreciated, thank you very much...

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
One way to do it is to read the file into a StringBuilder object.
StringBuilder provides an effecient way to manipulate string. Alternatively,
you can also treat your text file as a raw stream of bytes, and manipulate
it using the FileStream object, however I think this will be a bit more
trickier.

-- Ricky Lee
==================================================
^o^ "When all doors are closed, God will open a Windows" ^o^
==================================================
"lexicon" <ek******@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
Hello;
I have a text file. Assume that this file has some textual content. I
want to append a text into this file at a specific position; not to the
end of file. I assume that one way of doing this would be setting the
stream length, shifting the characters after the position + lengt to
the end, but this method seems inefficient to me. Another way might be,
storing the text content in an array and manipulating and writing this
array to the file, but this seems inefficient to me too.
Is there any way of doing this without the methods i thought about
above ? All ideas are appreciated, thank you very much...

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.