RPGLE string manipulation - Delete a String using %replace() and %scan()

Click here if you are looking for Find and Replace 


%REPLACE returns the character string produced by inserting a replacement string into the source string, starting at the start position and replacing the specified number of characters.

%REPLACE(replacement string: source string{:start position {:source
length to replace}})

%SCAN returns the first position of the search argument in the source string, or 0 if it was not found. If the start position is specified, the search begins at the starting position. The result is always the position in the source string even if the starting position is specified. The starting position defaults to 1.

%SCAN(search argument : source string {: start})

Deleting a String

Delete is easy just insert and empty string !
 $pos = %scan(%trim($scan_data):$string_data);   
 $string_data = %replace( ''       
                   : $string_data                   
                   : $pos                           
                   : %len(%trim($scan_data)));   

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.