在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;

您可以使用sql regexp函数。匹配字符串末尾3位数字的正则表达式是ddd$

这是一个很好的

d text            s             80a   varying
d match           s             80a   varying
d i5              s              5i 0
d numMatches      s             10i 0
/free
text        = 'steve 7335' ;
exec sql
set         :numMatches = regexp_count( :text, 'ddd$', 1 ) ;
if          numMatches > 0 ;
endif ;
text        = 'steve 733z3' ;
exec sql
set         :match :i5 = regexp_substr( :text, 'ddd$', 1, 1 ) ;
if          i5 = -1 ;
// not a match
endif ;

最新更新