API documentation for visualization library

Michael Galloy

single page | use frames     summary     class     fields     routine details     file attributes



includes main-level program

top vis_streplace

result = vis_streplace(str, pattern, replacement [, /evaluate] [, /fold_case] [, /global])

Handle string replacment with regular expressions.

Return value



str in required type=string

a string to search for expressions and replace them

pattern in required type=string

a regular expression possibly using subexpressions; see IDL's online help for STREGEX for help on regular expressions

replacement in required type=string

the string to replace matches of the "pattern"; can use $1, $2, etc. to refer to subexpressions in "pattern"


evaluate in optional type=boolean

set to evaluate the "replacement" as a IDL expression instead of just a string.

fold_case in optional type=boolean

set to make a case insensitive match with "pattern"

global in optional type=boolean

set to replace all expressions that match

start out optional private type=integral default=0

index into string of where to start looking for the pattern


The following example demonstrates basic operations of VIS_STREPLACE, simply replacing "was" with "was not" in the expression "Mike was here":

IDL> print, vis_streplace('Mike was here', 'was', 'was not') Mike was not here
Meta-variables $1, $2, etc. represent matched values in parentheses. This swaps the first two words in the string:
IDL> print, vis_streplace('Mike was here', '([^ ]*) ([^ ]*)', '$2 $1') was Mike here
Capitalize the name following "Mike". Here, EVALUATE and GLOBAL replace all patching expressions with an evaluated expression:
IDL> s = 'MikeGeorgeHenryMikeBill' IDL> re = 'Mike([A-Z][a-z]*)' IDL> expr = '"Mike" + strupcase($1)' IDL> print, vis_streplace(s, re, expr, /evaluate, /global) MikeGEORGEHenryMikeBILL
Another evaluated expression:
IDL> re = 'Mike([0-9]+)' IDL> expr = 'fix($1) * 2' IDL> help, vis_streplace('Mike5', re, expr, /evaluate) <Expression> LONG = 10
Here's an example to put grouping commas into a long integer value:
IDL> str = '1874382735872851' IDL> re = '^[+-]?([[:digit:]]+)([[:digit:]]{3})' IDL> for i = 0, strlen(str) / 3 - 1 do $ IDL> str = vis_streplace(str, re, '$1,$2', /global) IDL> print, str 1,874,382,735,872,851

Author information


Michael Galloy

File attributes

Modification date: Mon Nov 29 18:32:37 2010
Lines: 184
Docformat: rst rst