Hi ,
I have used REGEXP_COUNT to get the count of a string in a sentence like below and it was working fine in v7r2
select REGEXP_COUNT (trim('mastiff is stiffany '),trim(' iff '))
from SYSIBM/SYSDUMMY1
with NC
Result will be 2
However this sql statement wont work in old version .
So i am replacing this function with a similar RPGLE logic can you please help with a logic to get the count of a particular from in a string.
The search words are set up in a PF and string is something entered by user in display file interactively.Search words needs to be taken one by one from PF and needs to be searched in string entered by user in screen to check whether its present .So basically i am looking find the count of a particular word stored in a PF in the string using RPGLE code.
I am now planning to replace REGEXP_COUNT with an rpg logic. But below code is not working as expected . Can you please help with a logic to get the count
D W1string S 50a inz('mastiff is stiffany ')
D wkpos s 3p 0
D W1Tiff s 50a inz('iff ')
D W2Tiff s 4a
D W2string S 50a
D W3string S 50a
D Wkcount S 2P 0
D Wkupper C const('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
D wklower C const('abcdefghijklmnopqrstuvwxyz')
/free
eval w3string = %xlate(wklower:wkupper:w1string);
eval w2Tiff = %xlate(wklower:wkupper:w1Tiff);
eval wkpos = %scan(w2Tiff:W3String);
Dow wkpos <> *Zero;
Eval wkcount = wkcount + 1;
eval wkpos = wkpos + %len(w2Tiff);
eval wkpos = %scan(w2Tiff:W3String:wkpos);
Enddo;
dsply wkcount;
*inlr = *on;
This is my sample code which is not working as expected.
I have used REGEXP_COUNT to get the count of a string in a sentence like below and it was working fine in v7r2
select REGEXP_COUNT (trim('mastiff is stiffany '),trim(' iff '))
from SYSIBM/SYSDUMMY1
with NC
Result will be 2
However this sql statement wont work in old version .
So i am replacing this function with a similar RPGLE logic can you please help with a logic to get the count of a particular from in a string.
The search words are set up in a PF and string is something entered by user in display file interactively.Search words needs to be taken one by one from PF and needs to be searched in string entered by user in screen to check whether its present .So basically i am looking find the count of a particular word stored in a PF in the string using RPGLE code.
I am now planning to replace REGEXP_COUNT with an rpg logic. But below code is not working as expected . Can you please help with a logic to get the count
D W1string S 50a inz('mastiff is stiffany ')
D wkpos s 3p 0
D W1Tiff s 50a inz('iff ')
D W2Tiff s 4a
D W2string S 50a
D W3string S 50a
D Wkcount S 2P 0
D Wkupper C const('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
D wklower C const('abcdefghijklmnopqrstuvwxyz')
/free
eval w3string = %xlate(wklower:wkupper:w1string);
eval w2Tiff = %xlate(wklower:wkupper:w1Tiff);
eval wkpos = %scan(w2Tiff:W3String);
Dow wkpos <> *Zero;
Eval wkcount = wkcount + 1;
eval wkpos = wkpos + %len(w2Tiff);
eval wkpos = %scan(w2Tiff:W3String:wkpos);
Enddo;
dsply wkcount;
*inlr = *on;
This is my sample code which is not working as expected.
Comment