Search code examples
ibm-midrangerpglerpg

How to find the starting position of a specific word in a sentence in RPGLE


Suppose a sentence is "How is Kunal", how to find the starting position of word Kunal in that sentence using RPGLE.


Solution

  • You don't say what you've tried..

    But seems that %SCAN() would work

    dcl-s myString varchar(50);
    dcl-s posFound int(5);
     
    myString = 'How is Kunal';
    pos = %scan('Kunal':myString);
    if pos > 0;
      //found it 
    endif;