Append to string in Fortran
I have a very simple problem, that i am yet to find an answer to. Is there any way in which i can append a character, in particular a white space to a character that has already been initialized in FORTRAN. Apparently
CHARACTER(2000) :: result result = '' result = result//' '
Does not work. Thank you very much for your time!
What do you want to achieve? Of course it works, but it has not much use. Try the approach you have been already suggested in your previous question. In particular, be aware that all strings are filled with space after their last non-space character, this is very important!
'a'//' ' really produces 'a '
result = result//' '
produces a 2001 character string, which is then truncated on assignment, so that result ends up being the same.
You may want
result = trim(result)//' '
but it is also useless, because the string is filled with spaces anyway.
If you want to make the variable larger, you have to use:
character(:),allocatable:: result result = '' !now contains ' ' and has length 1 result = result//' ' !now contains ' ' and has length 2
You have to enable reallocation on assignment on some processors.