COBOL 替代 BASIC 的 MID 以及如何连接字符串?
我正在寻找 Visual Basic 的 MID 函数的 COBOL 替代方案。我需要做的就是从 8 个字符串中取出前 5 个字母并将它们连接起来。
我正在使用富士通COBOL。
非常感谢,
伊万
I'm looking for the COBOL alternative of Visual Basic's MID Function. The thing I need to do is take from 8 strings the first 5 letters and concatenate them.
I'm using Fujitsu COBOL.
Many thanks,
Yvan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Paxdiablo 给出了一些有效的方法来做到这一点。另一种方法是除了
STRING
动词之外还使用引用修饰。完整的程序示例如下:这大大减少了冗长,并在单个语句中捕获了串联。最好的建议是阅读
STRING
动词。它有多种创新的使用方式。COBOL 没有提供与 BASIC MID 语句完全相同的模拟。您可以通过使用
STRING
、UNSTRING
、INSPECT
和引用修改的某种组合来完成类似的操作。引用修改的一个示例是:SOME-VARIABLE-NAME(1:5)
- 1:5 位指定以SOME-VARIABLE-NAME
开头的子字符串第一个字符的长度为 5 个字符。修饰符本身可以是数值变量。STRING
和UNSTRING
动词提供了许多非常强大的功能。但总的来说,COBOL 并不是特别擅长字符串操作(有些人可能会说它在任何方面都不是特别擅长 - 但我不同意这种说法)。
Paxdiablo has given a couple of valid ways to do it. Another way would be to use reference modification in addition to the
STRING
verb. Complete program example follows:This cuts down on the verbosity quite a bit and captures the concatenation in a single statement. Best advice is to read up on the
STRING
verb. There are a number of innovative ways it can be used.COBOL does not provide an exact analogue to the BASIC MID statement. You can accomplish similar operations by using some combination of
STRING
,UNSTRING
,INSPECT
and reference modification. An example of a reference modification is:SOME-VARIABLE-NAME(1:5)
- the 1:5 bit specifies a substring ofSOME-VARIABLE-NAME
starting with the first character for a length of 5 characters. The modifiers may themselves be numeric variables. TheSTRING
andUNSTRING
verbs provide a number of features that can be quite powerful.In general though, COBOL is not particularly good at string manipulation (some might say its not particularly good at anything - but I would disagree with that statement).
我认为事情是这样的:
然后,你的字符串位于 TWENTY-FIVE-B 中。
你知道,我无法想象为什么人们认为 COBOL 很冗长:-)
更严重的是,我认为你可以沿着这些思路做一些事情来达到相同的结果(你可能必须摆弄开始和长度参数,我已经有一段时间没有认真做过 COBOL 了):
I think it goes something like this:
Then, your string is in
TWENTY-FIVE-B
.You know, I can't imagine why people thought COBOL was verbose :-)
On a more serious note, I think you can do something along these lines to achieve the same result (you may have to fiddle with the start and length parameters, it's been a while since I did any serious COBOL):
此子字符串示例页面显示了一些变化。一个例子:
This substring examples page shows a few variations. An example: