# Yahoo! UI Library

### substitute 3.0.0

Yahoo! UI Library > substitute > YUI~substitute
Search:
Filters
Show Private Show Protected Show Deprecated

## Class YUI~substitute

The following methods are added to the YUI instance

### Methods

#### substitute

`string substitute ( s , o , f )`
Does variable substitution on a string. It scans through the string looking for expressions enclosed in { } braces. If an expression is found, it is used a key on the object. If there is a space in the key, the first word is used for the key and the rest is provided to an optional function to be used to programatically determine the value (the extra information might be used for this decision). If the value for the key in the object, or what is returned from the function has a string value, number value, or object value, it is substituted for the bracket expression and it repeats. If this value is an object, it uses the Object's toString() if this has been overridden, otherwise it does a shallow dump of the key/value pairs if Y.dump is available (if dump isn't available, toString() is used). This method is included in the 'substitute' module. It is not included in the YUI module.

Parameters:
  `s <string>` The string that will be modified.
  `o <object>` An object containing the replacement values
  `f <function>` An optional function that can be used to process each match. It receives the key, value, and any extra metadata included with the key inside of the braces.

Returns: `string`
  the substituted string

Copyright © 2009 Yahoo! Inc. All rights reserved.