;+ ; ; @file_comments ; replace one (or more) character(s)/string(s) in a string array ; "modern" version of the obsolete strrepl ; ; @categories ; String ; ; @param STR {in}{required}{type=string array or scalar} ; the string to be changed ; ; @param EXP1 {in}{required}{type=scalar string} ; a single regular expression (as implemented by the STREGEX function). ; ; @param EXP2 {in}{required}{type=scalar string} ; replacement character/string ; ; @keyword FOLD_CASE ; Indicates that the regular expression matching should be done in a case-insensitive fashion. ; ; @returns ; string array or scalar ; ; @examples ; ; IDL> abc = 'abcdefghijklmnopqrstuvwxyz' ; IDL> print, strsed(abc, 'm', 'M') ; abcdefghijklMnopqrstuvwxyz ; IDL> print, strsed(abc, 'm.*t', 'M_T') ; abcdefghijklM_Tuvwxyz ; IDL> a = 'abcabcabc' ; IDL> help, strsed([abc, a, 'eee'], 'abc', 'XXX_') ; STRING = Array[3] ; IDL> print, strsed([abc, a, 'eee'], 'abc', 'XXX_') ; XXX_defghijklmnopqrstuvwxyz XXX_XXX_XXX_ eee ; ; @history ; Sept 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr) ; ; @version ; $Id$ ;- FUNCTION strsed, str, exp1, exp2, FOLD_CASE=fold_case ; compile_opt idl2, strictarrsubs ; strout = str line = stregex(strout, exp1) line = where(line NE -1, cnt) IF cnt GT 0 THEN BEGIN FOR i = 0L, cnt-1 DO $ strout[line[i]] = strjoin(strsplit(strout[line[i]], exp1, /extract $ , /regex, /preserve_null, FOLD_CASE = fold_case), exp2) ENDIF ; return, strout END