两个字符串的连接不起作用 [英] Concatenation of two strings does not work

查看:145
本文介绍了两个字符串的连接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,但它不起作用:

 字符* 260 xx,yy,zz 
xx ='A'
yy ='B'
zz = xx // yy

当我在Visual Studio中调试代码时,


  • 变量 xx 包含'A'
  • 变量 yy 包含'B'

  • 变量 zz 包含'A'



为什么不是 zz 包含'AB'?

解决方案

您定义 xx 长度为260个字符。分配较短的字符文字将导致带有空白的填充。因此, xx 包含 A 和259个空格。 yy 包含 B 和259个空格。所以连接字符串应该是'A' + 259空格+ 'B' + 259空格,共520个字符。

既然 zz 只有260个字符,其余的都会被裁剪。



您所要做的是通过

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

trim() 从字符串中删除尾随空白。

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'?

解决方案

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.

这篇关于两个字符串的连接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆