RPGLE string manipulation – Insert a String using %replace() as well as %scan()

Click hither if you lot are looking for Find in addition to Replace

%REPLACE returns the grapheme string produced past times inserting a replacement string into the beginning string, starting at the start rate in addition to replacing the specified position out of characters.

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

%SCAN returns the start rate of the search declaration inwards the beginning string, or 0 if it was non found. If the start rate is specified, the search begins at the starting position. The upshot is ever the rate inwards the beginning string fifty-fifty if the starting rate is specified. The starting rate defaults to 1.

%SCAN(search declaration : beginning string {: start})

Insert a String

One often-overlooked capability of %REPLACE is its might to insert a string.  Just ready the length to delete to 0, the %REPLACE BIF won’t delete whatever text from your string. Instead, it only inserts the information correct earlier the rate you lot specified.

$pos = %scan(%trim($scan_data):$string_data);     $string_data = %replace( %trim($replace_data)                          : $string_data                                      : $pos                                              : 0); 


Sumber http://www.mysamplecode.com/