0

I have a requirement to find the last occurrence of a character in a string in CL. For Example, If I have a string as Test_01_abc.Txt , and I have to get the last occurrence of '_'(Underscore), I need to get answer as 8(Which is the position of the second Underscore in the string). I am using 7.2 Version and %SCANR is not working here. One way is to go in a loop and search it. Is there a better way? THanks

jmarkmurphy
  • 11,030
  • 31
  • 59
AS400 User
  • 187
  • 2
  • 14

1 Answers1

1

%SCANR is an RPGLE built in function, not CLP. However, given that you are at v7.2, your only choce is to put QCLSCAN in a loop and find the last occurrance that way. There might be a way to do what you want in Python if you are willing to use that rather than CL.

jmarkmurphy
  • 11,030
  • 31
  • 59
  • Thanks Mark.. I have never used QCLSCAN API.. But here I can do the %SCAN and run it in a loop to get the last position.. is QCLSCAN any different? Kindly Advise.. – AS400 User Sep 07 '18 at 11:38
  • Looks like they have added quite a few built in functions for CL. %SCAN looks similar to QCLSCAN except QCLSCAN has a few more features like wildcard search, and replace capability. Still %SCANR is not an option for CLP even at v7.3. – jmarkmurphy Sep 07 '18 at 12:41
  • Thanks Mark! That helps – AS400 User Sep 07 '18 at 13:14