Concatenation of two strings does not work [duplic

2020-04-04 03:48发布

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条回答
Emotional °昔
2楼-- · 2020-04-04 04:13

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.

查看更多
登录 后发表回答