|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Access Single Line in Text FileHello Everybody,
is it possible to change a single line in a text file? Open "File" For Append only lets you insert at the end Open "File" For Binary has the problem that you never know how long a line actually is. Therefore the is no command like Line Input Unfortunately, now my wisdom ends... Thanks for reading Ole Weigelt Ole Weigelt wrote:
> If it isn't fixed-length records, then there really isn't a simple> Hello Everybody, > > is it possible to change a single line in a text file? > > Open "File" For Append only lets you insert at the end > Open "File" For Binary has the problem that you never know how long a line > actually is. Therefore the is no command like Line Input > > Unfortunately, now my wisdom ends... > way...if the file is relatively small it can be read to memory and manipulated there, then rewritten as one way.
Show quote
"Duane Bozarth" <dpboza***@swko.dot.net> schrieb im Newsbeitrag if the file is relatively small it can be read to memory andnews:428148D6.B87B49CF@swko.dot.net... > Ole Weigelt wrote: > > > > Hello Everybody, > > > > is it possible to change a single line in a text file? > > > > Open "File" For Append only lets you insert at the end > > Open "File" For Binary has the problem that you never know how long a line > > actually is. Therefore the is no command like Line Input > > > > Unfortunately, now my wisdom ends... > > > > If it isn't fixed-length records, then there really isn't a simple > way... > manipulated there, then rewritten as one way. That was what I wanted to avoid.But I thought that it is not that simple. Thanks Ole Ole Weigelt wrote:
Show quote > But, I pointed out the "all in memory" option as sometimes posters don't> "Duane Bozarth" <dpboza***@swko.dot.net> schrieb im Newsbeitrag > news:428148D6.B87B49CF@swko.dot.net... > > Ole Weigelt wrote: > > > > > > Hello Everybody, > > > > > > is it possible to change a single line in a text file? > > > > > > Open "File" For Append only lets you insert at the end > > > Open "File" For Binary has the problem that you never know how long a > line > > > actually is. Therefore the is no command like Line Input > > > > > > Unfortunately, now my wisdom ends... > > > > > > > If it isn't fixed-length records, then there really isn't a simple > > way... > > if the file is relatively small it can be read to memory and > > manipulated there, then rewritten as one way. > > That was what I wanted to avoid. > > But I thought that it is not that simple. .... think of it.... Note also that if you change the length of the line in the manipulation, you'll have to rewrite the file from that point on anyway...
Show quote
"Ole Weigelt" <o.weigelt@officeworks> wrote in message You can use Line Input to read each line in and write it to a temp file. news:OqmdIAcVFHA.3808@TK2MSFTNGP14.phx.gbl... > > "Duane Bozarth" <dpboza***@swko.dot.net> schrieb im Newsbeitrag > news:428148D6.B87B49CF@swko.dot.net... >> Ole Weigelt wrote: >> > >> > Hello Everybody, >> > >> > is it possible to change a single line in a text file? >> > >> > Open "File" For Append only lets you insert at the end >> > Open "File" For Binary has the problem that you never know how long a > line >> > actually is. Therefore the is no command like Line Input >> > >> > Unfortunately, now my wisdom ends... >> > >> >> If it isn't fixed-length records, then there really isn't a simple >> way... > > > if the file is relatively small it can be read to memory and >> manipulated there, then rewritten as one way. > > That was what I wanted to avoid. > > But I thought that it is not that simple. > > Thanks > > Ole > When you find the line you want to change, change it and write it. Then read in all remaining lines and write to the temp file. Finally delete the original file and rename the temp file. Sort of clunky but I cannot think of a better way that does not involve having the whole file in memory. -- Peter Aitken Remove the crap from my email address before using.
Show quote
"Peter Aitken" <pait***@CRAPnc.rr.com> schrieb im Newsbeitrag This is exactly what I do now. I was hoping to find a nicer solution, butnews:OKWAK$iVFHA.3572@TK2MSFTNGP12.phx.gbl... > "Ole Weigelt" <o.weigelt@officeworks> wrote in message > news:OqmdIAcVFHA.3808@TK2MSFTNGP14.phx.gbl... > > > > "Duane Bozarth" <dpboza***@swko.dot.net> schrieb im Newsbeitrag > > news:428148D6.B87B49CF@swko.dot.net... > >> Ole Weigelt wrote: > >> > > >> > Hello Everybody, > >> > > >> > is it possible to change a single line in a text file? > >> > > >> > Open "File" For Append only lets you insert at the end > >> > Open "File" For Binary has the problem that you never know how long a > > line > >> > actually is. Therefore the is no command like Line Input > >> > > >> > Unfortunately, now my wisdom ends... > >> > > >> > >> If it isn't fixed-length records, then there really isn't a simple > >> way... > > > > > > if the file is relatively small it can be read to memory and > >> manipulated there, then rewritten as one way. > > > > That was what I wanted to avoid. > > > > But I thought that it is not that simple. > > > > Thanks > > > > Ole > > > > You can use Line Input to read each line in and write it to a temp file. > When you find the line you want to change, change it and write it. Then read > in all remaining lines and write to the temp file. Finally delete the > original file and rename the temp file. Sort of clunky but I cannot think of > a better way that does not involve having the whole file in memory. > now I will keep it that way Thanks to both of you for your help!! Show quote > > -- > Peter Aitken > > Remove the crap from my email address before using. > > |
|||||||||||||||||||||||