%SCAN()


search argument : string to be searched {:start position}
First position of search argument in string or zero, if not found.

There are two very big differences between these two BIFs.

  • The first is that with %CHECK, the compare string is treated as a list of individual characters, whereas %SCAN operates on it as a single string. 
  • The second is that %SCAN tries to locate an occurrence of the characters in the compare string, whereas %CHECK tries to identify any characters that are not present in the compare string.

Remember: The operations are case-sensitive.

D $source         S            100A                   
D $pos            S              5U 0                 
                                                       
 /FREE                                               
                                                       
   $source = 'RPGLE is a Popular Programming ' +      
             'language of the IBM Power i platform';  
                                                       
   $pos = %scan ('IBM' : $source);                    
   dsply $pos; //DSPLY     48                         
                                                       
   $pos = %scan ('IBM' : $source :15);                
   dsply $pos; //DSPLY     48                         
                                                       
   $pos = %scan ('Po' : $source);                     
   dsply $pos; //DSPLY     12                         
                                                       
   $pos = %scan ('Po' : $source : 20);                
   dsply $pos; //DSPLY     52                         
                                                       
    *inlr = *on;                                      
 /END-FREE                                           

 

Post Comments