473,378 Members | 1,207 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,378 software developers and data experts.

"Insert" (not append) new text segment to an existing text file

sm
How to "Insert" (not append) new text segment to an existing text file?

Assume that we have text file as shown below;
Elvis
Sofia
Kylix
BCB--> How to insert here?
Atten
BuilderX
Roma
Together
Cairo
Jul 23 '05 #1
2 2778
sm wrote:
How to "Insert" (not append) new text segment to an existing text file?

Assume that we have text file as shown below;
Elvis
Sofia
Kylix
BCB--> How to insert here?
Atten
BuilderX
Roma
Together
Cairo


This has nothing to do with the language. Open the file for reading,
open another file (new one) for writing. Begin reading the first one
and writing to the new one until you hit the spot where you need to
insert something. Now, write what you need inserted. Once done, go
on with "copying" the contents of the original file. Another possible
solution is to read the entire contents of the file into some memory
structure, insert what you need into that structure, then write that
structure out to the same file again (after re-opening it for writing).

V
Jul 23 '05 #2
sm wrote:
How to "Insert" (not append) new text segment to an existing text file?
You cannot insert new data into the file. You can replace existing data with
new data (as long as the size stays the same), and you can append, but you
cannot add or remove data at any other place than the end.
If you need that, you basically have to copy the whole contents of the file
over to a new file, inserting the new data at the right place. Then rename
it back to the original file name.
Assume that we have text file as shown below;
Elvis
Sofia
Kylix
BCB--> How to insert here?
Atten
BuilderX
Roma
Together
Cairo


Jul 23 '05 #3

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

Similar topics

4
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want...
5
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5...
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
4
by: Takeadoe | last post by:
Dear NG - I've got a bunch of SQL statements (Insert Into "Access Table Name") generated from another software program. They look like this: Pasting these lines into the SQL view as they are...
4
by: Bart op de grote markt | last post by:
Hello I used to work in a Sybase database environment. When I had to insert/ update records in the database, I always used "insert on existing update", in this way, you didn't have to check...
13
by: shankindc | last post by:
Hi, I have a data entry form which opens default values each time the form is open. Requirement is that users can edit existing data in the form. When the form is closed, it shouldnt update the...
1
jhardman
by: jhardman | last post by:
I know this question deals with a lot of SQL, but I am applying it to ASP, so I think this is the best place for it. When I learned SQL, I saw the "insert" command as very useless. It tries to do...
2
by: teric2 | last post by:
Hello again. I have the following code attached to the onclick event of a command button: Dim strQry As String strQry = "INSERT INTO () VALUES ('" & Me!Text80 & "')" DoCmd.RunSQL...
3
Minion
by: Minion | last post by:
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge. First though I'll goto into the overview...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.