如何计算RPG中字符串中相同字母的数量

How to count the number of identical letters in a string in RPG

我想数一数姓名'olivia'中'i'的个数,但我觉得我的条件不成立?

请问如何在RPG 4中做charAt?

FOR i = 1 to %len(name);
  IF %check(name : letter) = 0;
    count += 1;

  ENDIF;

ENDFOR;

完整代码如下:

**free

dcl-s name        varchar(50);
dcl-s letter      char(1);
dcl-s count       packed(2:0);
dcl-s i           packed(3:0);
dcl-s waitInput   char(1);
dcl-s message     varchar(50);

name = 'olivia';
letter = 'i';
count = 0;

FOR i = 1 to %len(name);
  IF %check(name : letter) = 0;
    count += 1;

  ENDIF;

ENDFOR;

message = 'The name ' + %char(name) + ' has ' + %char(count) + 'time(s) the letter ' + (letter) ;
dsply message '' waitInput;

*INLR = *on;
IF %check(name : letter) = 0;

=>

 IF %subst(name :i:1) = letter;