source: trunk/SRC/ToBeReviewed/STRING/strsed.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1;+
2;
3; @file_comments
4; replace one (or more) character(s)/string(s) in a string array
5; "modern" version of the obsolete strrepl
6;
7; @categories
8; String
9;
10; @param STR {in}{required}{type=string array or scalar}
11; the string to be changed
12;
13; @param EXP1 {in}{required}{type=scalar string}
14; a single regular expression (as implemented by the STREGEX function).
15;
16; @param EXP2 {in}{required}{type=scalar string}
17; replacement character/string
18;
19; @keyword FOLD_CASE
20; Indicates that the regular expression matching should be done in
21; a case-insensitive fashion.
22;
23; @returns
24; string array or scalar
25;
26; @examples
27;
28;   IDL> abc = 'abcdefghijklmnopqrstuvwxyz'
29;   IDL> print, strsed(abc, 'm', 'M')
30;    abcdefghijklMnopqrstuvwxyz
31;   IDL> print, strsed(abc, 'm.*t', 'M_T')
32;    abcdefghijklM_Tuvwxyz
33;   IDL> a = 'abcabcabc'
34;   IDL> help, strsed([abc, a, 'eee'], 'abc', 'XXX_')
35;    <Expression>    STRING    = Array[3]
36;   IDL> print, strsed([abc, a, 'eee'], 'abc', 'XXX_')
37;    XXX_defghijklmnopqrstuvwxyz XXX_XXX_XXX_ eee
38;
39; @history
40; Sept 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
41;
42; @version
43; $Id$
44;-
45FUNCTION strsed, str, exp1, exp2, FOLD_CASE=fold_case
46;
47  compile_opt idl2, strictarrsubs
48;
49  strout = str
50  line = stregex(strout, exp1)
51  line = where(line NE -1, cnt)
52  IF cnt GT 0 THEN BEGIN
53    FOR i = 0L, cnt-1 DO $
54       strout[line[i]] = strjoin(strsplit(strout[line[i]], exp1, /extract $
55                                          , /regex, /preserve_null, FOLD_CASE = fold_case), exp2)
56  ENDIF
57;
58  return, strout
59END
Note: See TracBrowser for help on using the repository browser.