- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
how do i append a text in a text file, which already includes text?
Like this:
Text in File before opening within Fortran: "Hello"
Opening File in Fortran
Write Text to File within Fortran: "World"
Close File in Fortran
Text in File after closing within Fortran: "Hello World"
Hope you can help me, cause opening and writing a text (regardless binary or text mode) is not the problem....just the text appending.
Regards
Oliver
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can specify position="append".
Then the file pointer will be positioned to the end of the file.
However, if you want to append to the previous _line_, that requires preparation:
you need to write that last line via advance="no", so that the newline which is
normally added is suppressed.
As far as I know, you can not go back one character in the file, unless you use
stream access on a text file, but then the problem is: is the newline a single
character or is it carriage-return - linefeed?
Regards,
Arjen
Then the file pointer will be positioned to the end of the file.
However, if you want to append to the previous _line_, that requires preparation:
you need to write that last line via advance="no", so that the newline which is
normally added is suppressed.
As far as I know, you can not go back one character in the file, unless you use
stream access on a text file, but then the problem is: is the newline a single
character or is it carriage-return - linefeed?
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suppose you want to write "World, Hello" when you already have "Hello".
You will have to replace the contents of the record with the string "World, Hello".
It's the same with wanting to replace "Hello" with "Hello World".
So you have to rewind the file, move the file marker to the beginning of the record
that you are interested in and then write your new contents to it.
If you have a string variable containing "Hello", and a string variable containing " World" then you can append another string to it in your code by using
helloworldstring=trim(hellostring)//trim(worldstring)
provided that helloworldstring has been sized long enough. You can then WRITE the whole string to the record using A format.
Otherwise you just output the two strings back to back to the record using a WRITE and A format.
You will have to replace the contents of the record with the string "World, Hello".
It's the same with wanting to replace "Hello" with "Hello World".
So you have to rewind the file, move the file marker to the beginning of the record
that you are interested in and then write your new contents to it.
If you have a string variable containing "Hello", and a string variable containing " World" then you can append another string to it in your code by using
helloworldstring=trim(hellostring)//trim(worldstring)
provided that helloworldstring has been sized long enough. You can then WRITE the whole string to the record using A format.
Otherwise you just output the two strings back to back to the record using a WRITE and A format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to both of you for your answers.
@arjenmarkus:
Well...i did not expect, that the solution is quite that easy.
Because i alwaysonly need to append text at the end of the file, theposition="append" flag is enough for me.
Many thanks :)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page