RPGLE中如何获取角色类型变量的长度?
RPGLE中有没有简单的方法可以直接返回字符和类型变量的长度?我这里所说的长度并不是D-spec中规定的长度。我说的是字符串中有意义的字符的实际数量。假设一个字符类型变量定义为50个字符长,并为其赋值“Hello world!”,那么我想要的长度是12,即从“H”到“!”。前导和尾随空白将被忽略。有什么简单的方法可以做到这一点吗?
Is there any easy way to directly return the length of character and type variable in RPGLE? The length I am talking about here is not the length specified in the D-spec. I am talking about the actual number of meaningful characters in a string. Let's say a character type variable is defined to be 50 characters long, and it is assigned with value 'Hello world!', then the length I want is 12, which is from 'H' to '!'. The leading and trailing blank is ignored. Is there any simple way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
%len(%trimr(field))
,它会在检查长度之前修剪尾随空格。%triml
修剪前导空格(左侧)%trimr
修剪尾随空格(右侧)%trim
修剪前导和尾随空格You can use
%len(%trimr(field))
, which trims trailing spaces before checking the length.%triml
trims leading spaces (on the left)%trimr
trims trailing spaces (on the right)%trim
trims leading and trailing spaces看起来您要查找长度的字段是固定字符字段,例如
如果我们执行 eval msg = 'Hello, World!'那么 msg 不包含“Hello, World!” - 它包含“你好,世界!” ' 也就是说,它有一堆空白来将其填充到 40 个字符。根据定义,这就是固定长度字段的工作方式。
%trimr() 可以很好地处理这些字符,它甚至有一个可选参数来定义应该修剪哪些字符。
另一方面,如果您要使用可变长度字段
,然后执行 eval msg = 'Hello, World!'那么该字段实际上只包含分配给它的字符。在这种情况下,不需要%trimr(); %len() 将返回字段的当前长度。
It looks like the field you are trying to find the length of is a fixed character field, like
If we do an eval msg = 'Hello, World!' then msg does not contain 'Hello, World!' - it contains 'Hello, World! ' That is, it has a pile of blanks to pad it out to 40 characters. That's how fixed length fields work by definition.
%trimr() can work very well with these, and it even has an optional parameter to define which characters should be trimmed.
On the other hand, if you were to use a varying length field
and then did an eval msg = 'Hello, World!' then the field actually contains only the characters assigned to it. In this case, no %trimr() is needed; %len() will return the current length of the field.