如何计算字符串中的元音?
例如:
data: str type string value 'steave'.
我希望输出是:
2 --> e.
1 --> a.
只需遍历字符串/字符并将结果收集到统计内部表中即可。使用CA
(包含任何(运算符检查元音。示例代码:
DATA: str TYPE string VALUE 'steave',
l_pos TYPE sy-index,
BEGIN OF ls_stat,
char TYPE c,
count TYPE sy-index,
END OF ls_stat,
lt_stat LIKE STANDARD TABLE OF ls_stat.
DO strlen( str ) TIMES.
l_pos = sy-index - 1 .
IF str+l_pos(1) CA 'AaEeIiOoUu'.
ls_stat-char = str+l_pos(1).
ls_stat-count = 1.
COLLECT ls_stat INTO lt_stat.
ENDIF.
ENDDO.
SORT lt_stat BY count DESCENDING.
LOOP AT lt_stat INTO ls_stat.
WRITE: / ls_stat-count, '->', ls_stat-char.
ENDLOOP.
我真的认为你在随意编造单词。我希望"vogals"是角色。我被告知,Vogals是元音。谢谢@jmoerdyk。无论如何,既然你让我感兴趣,我认为这可能会起作用:
vowels = 'aeiouy'
length = STRLEN(vowels).
WHILE index < length.
char = vowels+index(1).
FIND ALL OCCURENCES OF char IN yourString
MATCH COUNT occurrences
WRITE: / char,'appears', / occurrences,'times'
ADD 1 TO index.
ENDWHILE.
为 SAP 工作似乎很困难。该语言似乎适用于表/数据库,而不是这些字符串操作。