Modify txt file [message #85039] |
Wed, 26 June 2013 00:43  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
Hi,
I've pretty much read text files pretty often, but haven't manage to modify a text file in a fast way...
Here is the thing. Consider a text file like this:
parameter1 = 5
parameter3 = 2
parameter2 = 8
parameter7 = 23
I would like to change a line 3 to:
parameter2 = 9
Is there a quick way to do this? At the moment I'm reading the file and storing it in an string array, modifying the selected string and rewriting the whole file. Alternatively, I could write in parallel to another file and then do renaming. But I thought that there should be a smarter way using OPENU, but this way I insert a line and not substitute it... or?
Regards,
Helder
|
|
|
|
|
Re: Modify txt file [message #85053 is a reply to message #85043] |
Wed, 26 June 2013 13:43  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, June 26, 2013 4:19:16 PM UTC+2, David Fanning wrote:
> Helder writes:
>
>
>
>> I've pretty much read text files pretty often, but haven't manage to modify a text file in a fast way...
>
>> Here is the thing. Consider a text file like this:
>
>> parameter1 = 5
>
>> parameter3 = 2
>
>> parameter2 = 8
>
>> parameter7 = 23
>
>>
>
>> I would like to change a line 3 to:
>
>> parameter2 = 9
>
>>
>
>> Is there a quick way to do this?
>
>
>
> Do you find this slow? This is the way I've always done it with
>
> configuration files. It has never seemed slow to me.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Hi, thanks for the answers.
In my example I used numbers and that is not actually the only thing I'm dealing with. Some of the fields refer to directories and these change (in length) all the time.
David: I don't find it slow, but sometimes I have the feeling I'm making things more complicated and "you" guys have better ways...
Thanks anyhow... now I feel like I'm doing the right thing :-)
Cheers,
Helder
|
|
|