AS/400: Find repeated character in a given string

620 pts.
Tags:
AS/400
RPG
String
It's a general question, I need to find out repeated character in a given string. Please advise. Program:
0001.00 DSTR              S              8A   INZ('ABDACB')

0002.00 DSTR1             S              1A

0002.01 DLEN              S              2S 0

0002.02 DPOS              S              2S 0

0002.03 DI                S              2S 0 INZ(1)

0003.00 C                   EVAL      LEN=%LEN(%TRIM(STR))

0004.00 C                   DOW       LEN>0

0005.00 C                   EVAL      STR1=%SUBST(STR:I:1)

0006.00 C                   EVAL      POS=%SCAN('STR1': STR)

0006.01 C     STR1          DSPLY

0007.00 C     POS           DSPLY

0009.00 C                   EVAL      I=I+1

0010.00 C                   ENDDO

0011.00 C                   SETON                                        LR
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try removing the quotes in this statement and add a starting position.

EVAL      POS=%SCAN(STR1: STR : 1)

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb

    I suppose I is the position in the string

    In your code

    DOW       LEN>0

    would all ways be true .. you never update LEN

    Perhaps that should be

    DOW       LEN > I

    0006.00 C                   EVAL      POS=%SCAN('STR1': STR)

    Since you want to scan for the character that you just put into the variable STR1, take the quotes off of STR1

    0006.00 C                   EVAL      POS=%SCAN(STR1: STR)

    But this will find the first character in the string that matches .. you want the character beyond that

    0006.00 C                   EVAL      POS=%SCAN('STR1': STR : I + 1)

    you want to start the scan at position I + 1 of the string




    54,090 pointsBadges:
    report
  • chowas400
    Thank you very much Philp...
     i got the excepted output now.


    620 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: