在 COBOL 中连接未知长度的字符串
如何在 COBOL 中将两个长度未知的字符串连接在一起? 例如:
WORKING-STORAGE.
FIRST-NAME PIC X(15) VALUE SPACES.
LAST-NAME PIC X(15) VALUE SPACES.
FULL-NAME PIC X(31) VALUE SPACES.
如果 FIRST-NAME = 'JOHN '
和 LAST-NAME = 'DOE '
,我怎样才能得到:
FULL-NAME = 'JOHN DOE '
而不是:
FULL-NAME = 'JOHN DOE '
How do I concatenate together two strings, of unknown length, in COBOL? So for example:
WORKING-STORAGE.
FIRST-NAME PIC X(15) VALUE SPACES.
LAST-NAME PIC X(15) VALUE SPACES.
FULL-NAME PIC X(31) VALUE SPACES.
If FIRST-NAME = 'JOHN '
and LAST-NAME = 'DOE '
, how can I get:
FULL-NAME = 'JOHN DOE '
as opposed to:
FULL-NAME = 'JOHN DOE '
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信下面的内容会给你你想要的。
I believe the following will give you what you desire.
乍一看,解决方案是使用对 STRING 的引用修改将两个字符串(包括空格)连接在一起。 问题是您必须知道 FIRST-NAME 中存在多少个尾随空格,否则您将生成类似“JOHNbbbbbbbbbbbbDOE”的内容,其中 b 是空格。
没有内在的 COBOL 函数来确定字符串中尾随空格的数量,但有一个可以确定字符串中前导空格的数量。 因此,据我所知,最快的方法是反转名字,找到前导空格的数量,并使用引用修改将名字和姓氏串在一起。
您必须将这些字段添加到工作存储中:
At first glance, the solution is to use reference modification to STRING together the two strings, including the space. The problem is that you must know how many trailing spaces are present in FIRST-NAME, otherwise you'll produce something like 'JOHNbbbbbbbbbbbbDOE', where b is a space.
There's no intrinsic COBOL function to determine the number of trailing spaces in a string, but there is one to determine the number of leading spaces in a string. Therefore, the fastest way, as far as I can tell, is to reverse the first name, find the number of leading spaces, and use reference modification to string together the first and last names.
You'll have to add these fields to working storage:
您可以尝试制作一个循环以获得实际长度。
You could try making a loop for to get the real length.