Concatenation of two strings does not work [duplicate]

空扰寡人 提交于 2019-12-01 16:56:38

问题


I have the following code, but it doesn't work:

 CHARACTER*260 xx, yy, zz     
  xx = 'A'   
  yy = 'B'
  zz = xx // yy

When I debug my code in Visual Studio the

  • variable xx contains 'A'
  • variable yy contains 'B'
  • variable zz contains 'A'

Why doesn't zz contain 'AB'?


回答1:


You defined xx to be 260 characters long. Assigning a shorter character literal will result in a padding with blanks. Thus, xx contains A and 259 blanks. yy contains B and 259 blanks. So the concatenated string would be 'A' + 259 blanks + 'B' + 259 blanks, in total 520 characters.

Since zz is only 260 characters long, the rest is cropped.

What you are trying to do is achieved by

zz = trim(xx) // trim(yy)

trim() removes trailing whitespace from strings.



来源:https://stackoverflow.com/questions/31134182/concatenation-of-two-strings-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!