473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1835

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******** ******@TK2MSFTN GP12.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
5764
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 use of checkpoints (for simple recovery and Backup Log for full recovery). On several website people speak about full transaction log and the pace of growing can't keep up with the update. Therefore we want to create a script which flushes the...
6
6695
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 = File.AppendText(myFILENAME) objStreamWriter.WriteLine(csvline) objStreamWriter.Close() The code works fine but I need to be a ble to delete the entire contents of the file as well and I cant figure it out.
9
1510
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, causes headers to be generated into the HTTP headers! I have no explanation as to how it does that, it just does that! I have tried everything I can think of,
3
4425
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 view, I simply want to append some text to the view of this field in the form using the control source. The field name is: artist. This works fine for the control source: artist
5
1643
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, 2, 3, 4, 5, 6, etc without manually going in and changing those numbers?
3
2470
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 problem is I don't see the items added to the listbox unless I use
1
1706
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 adding updating and deleting user in linux.adds a user to the database file called passwd. With the -a switch the program accepts a user-id and then prompts for a password, and a conformation. The username and password are then added to the passwd...
2
1159
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. This appeared to work, but the sequence numbers in my ID column just continued on - they didn't "refresh" back to 1. Do you know how to get the numbers to restart back to 1 besides deleting the whole table and recreating it from scratch? Is it...
1
4666
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 question is if it's safe to remove this file ? The reason I ask if because I try to find out which file are nessesary for
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.