在RPGLE中,如何检查10大小变量的最后3个字符是否为数字

我有一个大小为 10 的变量。它存储一个 10 大小的值,如“KUNAL12345”。如何检查值的最后 3 个字符是否为数字。在这种情况下,最后 3 个字符是 345,它是数值。

回答

你可以像这样使用%check(我没有测试)

dcl-c digits '0123456789';
dcl-s value char(10) inz('KUNAL12345');
if %check(%subst(value:8:3):digits) = 0;
  // each of the three last characters is a digit character
endif;

或如@jtaylor 所说

if %checkr(value:digits) < 8;
  // each of the three last characters is a digit character
endif;

  • For the %CHECK case, instead of hardcoding the 8, you could use %SUBST(VALUE:%LEN(VALUE)-2) to start at the third-last character and go to the end of the string (no "length" parameter needed). But ... this isn't ideal either, since "2" isn't very self-documenting for "third last character".

以上是在RPGLE中,如何检查10大小变量的最后3个字符是否为数字的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>