在COBOL中订阅字符串文字 [英] SUBSTRING for a String Literal in COBOL
问题描述
是否有在不使用临时变量的情况下在COBOL中获取字符串文字的SUBSTRING的方法?
Is there anyway to get a SUBSTRING of string literal in COBOL without using a temporary variable?
在下面的代码中说:
MOVE "HELLO" TO MY-VAR.
MOVE MY-VAR(1:3) TO SUB-STR.
有没有办法做同样的事情,但是没有 MY-VAR
?
Is there any way to do the same thing, but without MY-VAR
?
编辑:
我确实尝试了以下代码,但是失败了。
I did tried following code, but it's failed.
MOVE "HELLO"(1:3) TO SUB-STR * COMPILE ERROR
推荐答案
您可以通过使用函数对文字进行类型清洗来完成您想做的事情。然后,您可以对函数的输出进行子字符串化或引用修改。考虑对同一数据调用两次reverse会返回原始数据。
You can accomplish what you are trying to do by type-laundering the literal through a function. You can then substring, or reference modify, the output of the function. Consider that calling reverse twice on the same data returns the original data.
Move function reverse
( function reverse(
'abcdefg'
)
) (3:1) to text-out
以上内容将导致 c文本输出。
The above will result in a 'c' being moved to text-out.
这篇关于在COBOL中订阅字符串文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!