strings/
mg_subs.pro
includes main-level programString substitution routine which substitutes values into a given string using the correspondences found in the provided hash or structure.
Examples
A single hash or structure can be created with all the possible values needed and then a template string can selectively access the desired values. For example, create a hash of a couple values:
IDL> h = hash('name', 'Mike', 'height', 72)
name
key can be used to access just one of the keys in
the hash:
IDL> print, mg_subs('Name: %(name)s', h)
Name: Mike
But the other (or all of the other) attributes can also be accessed:
IDL> print, mg_subs('Height: %(height)d inches', h)
Height: 72 inches
IDL> .run mg_subs
IDL> print, mg_subs('%(name)s is located in zip code %(zipcode)05d.', $
IDL> { name: 'Exelis VIS', zipcode: 80301 })
Exelis VIS is located in zip code 80301.
IDL> h = hash('loc', 'Boulder, CO', 'temp', 80, 'units', 'degrees F')
IDL> print, mg_subs('It is %(temp)d %(units)s in %(loc)s today!', h)
It is 80 degrees F in Boulder, CO today!
IDL> obj_destroy, h
Other file information
- Requires:
IDL 8.0
Routines
top mg_subs
result = mg_subs( [template], hash [, unresolved_keys=long])
String substitution routine which substitutes values into a given string using the correspondences found in the provided hash or structure.
Return value
string
Parameters
- template in optional type=string
string to substitute into
- hash in required type=hash/structure
hash table or structure with key-value pairs to subsitute into the template
Keywords
- unresolved_keys out optional type=long
set to a named variable to retrieve the number of keys that were not found in the hash; if passed, no error message is output
File attributes
Modification date: | Wed May 14 15:07:14 2014 |
Lines: | 68 |
Docformat: | rst rst |
Contact me if you have enhancement requests or bug fixes.