473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Updating text file (without deleting/recreating)

What classes/methods can I use to do the following?

1. Open a text file (less than 50k in size)
2. Replace some text in it.
3. Close the text file.

I don't want to have to create a new file in order to accomplish this (i.e.,
I don't want to open it, read to memory, do replacement in memory, delete
original file, write to new file from memory).

Thanks!
Nov 17 '05 #1
2 1827

Jeffrey wrote:
What classes/methods can I use to do the following?

1. Open a text file (less than 50k in size)
2. Replace some text in it.
3. Close the text file.

I don't want to have to create a new file in order to accomplish this (i.e.,
I don't want to open it, read to memory, do replacement in memory, delete
original file, write to new file from memory).

Thanks!


Take a look at the BufferedStream class, which I think will do what you
want. The Seek method will allow you to go to a given position and then
you can write to the file with Write.

If you are looking for specific text in the file, you are going to need
to either know exactly where it is (offset) or find it by reading until
you find it.

matt

Nov 17 '05 #2
Jeff,

I think the only way you could accomplish this is in case the length of the
text you want to write equals the length of the text you want to replace.
Then you could treat the file as a stream of characters and Seek() into the
desired position in order to replace the text.
See:

http://msdn.microsoft.com/library/de...sseektopic.asp

Being such small files (<50K) I think the "standard" approach (read from a
file and write into another) could work very fast.

Regards - Octavio

"Jeffrey" <JT*@nospam.net> escribió en el mensaje
news:um**************@TK2MSFTNGP12.phx.gbl...
What classes/methods can I use to do the following?

1. Open a text file (less than 50k in size)
2. Replace some text in it.
3. Close the text file.

I don't want to have to create a new file in order to accomplish this
(i.e., I don't want to open it, read to memory, do replacement in memory,
delete original file, write to new file from memory).

Thanks!

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
6
by: Poppy | last post by:
I use the following code to append a line of text to a text file : Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName) Dim objStreamWriter As StreamWriter objStreamWriter =...
9
by: comp.lang.php | last post by:
<?php if (headers_sent()) print_r('headers sent'); // do other stuff ?> I have a file, "classes.inc.php", a library of PHP version 4+ classes. This library file, the moment it is included,...
3
by: ChasW | last post by:
This should be most simple to do, and I am doing it elsewhere in the very same form, but for some reason it is not working in this case. My form uses a query as its Record Source. In the form...
5
by: cover | last post by:
After a while of deleting records in a MySQL db, there gets to be the gaps in the id numbering system. i.e. 1, 2, 3, 6, 7, 12, and so on. Is there a way to renumber the id system in a table for 1,...
3
by: R. Harris | last post by:
Hi. I have 2 forms: form1 form2 On Form2 I have a listbox and a button. When I click the button it calls a function from form1 and within that function it updates the listbox on form2. My...
1
by: smartchap009 | last post by:
Adding,Updating and Deleting user using perl script in linux -------------------------------------------------------------------------------- hi, If i can get help in writing perl code for...
2
by: notsosavy | last post by:
Each month I will be updating a table in my database using data from a spreadsheet. I thought that I could just Copy/Paste from the spreadsheet and Ctrl A/Ctrl V and paste the info into the table. ...
1
by: Tony | last post by:
Hello! I use VS2005 and within folder properties there is a file called Settings.setting. I can remove this file and rebuild the application without any kind of error or problems. So my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.