两个字符串的连接不起作用

编程入门 行业动态 更新时间:2024-10-11 19:15:38
本文介绍了两个字符串的连接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

字符* 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.

更多推荐

两个字符串的连接不起作用

本文发布于:2023-11-30 07:56:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   不起作用   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!