Apparently not able to append a string to another

前端 未结 1 494
青春惊慌失措
青春惊慌失措 2021-01-19 10:48

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 t

相关标签:
1条回答
  • 2021-01-19 11:34

    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 '
    

    but

    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.

    0 讨论(0)
提交回复
热议问题