idllib

Personal IDL library for M. Galloy

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

strings/

mg_subs.pro

includes main-level program

String 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)
If desired, the 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
The main-level program at the end of this file also contains examples. Run them with:
IDL> .run mg_subs
This does the following examples:
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

top source mg_subs

result = mg_subs( [template], hash)

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

File attributes

Modification date: Wed Nov 2 15:40:32 2011
Lines: 147
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.