![]() |
Business Internet Services |
|
Replace is used to replace tokens in a target String with runtime parameter values. The tag can do this in three different ways. The method is determined by the number of tokens and the number of parameter values. Tokens are specified by the token attribute. If a single token is used it must be a char (like , $, #) that you want to replace with runtime values in the target. If multiple tokens are used they can be char strings separated by commas. Searching the target for a single token char is more efficient than searching for multiple char strings. Values are supplied by parameter names at runtime. Parameter names are listed in the value attribute. Multiple parameter names must be separated by commas. Method one: single token char, single parameter. All the tokens in the target are replaced by the runtime parameter value. If the parameter returns an array of multiple values they will be used in sequence to replace tokens. If there are more tokens than values, the values will be repeated. Method two: single token char, mulitiple parameters. A value array is contructed to hold the first runtime value from each parameter. The number of values will be equal to the number of parameter names. The value array will be used to replace tokens in the target. If there are more tokens than values, the values will be repeated. Method three: multiple tokens, multiple values. Each token is paired with a single parameter value. All occurrences of a specific token in the target will be replaced by a single value from the paired parameter. This method is slightly slower because the target is processed separately for each token/value pair. It is more flexible because you can match parameter names in the target with parameter values. The speed penalty is not significant for small target files. Here are some exaples... Insert a paramter value into a block of static text and store the text
as a runtime parameter value named newText (method one).
Get a stored target from the request and replace tokens with a value that
is also stored in the request (method one).
Read a text file uisng a ReadText tag and replace tokens with values (method two).
Read a text file uisng a ReadText tag and replace tokens with values obtained
from a String[][] or a String[]. This can be used to fill a template from a record.
Read a text file and replace words with parameter values (method three).
@author Mark Ashworth @version 0.3, 2001-06-26 Return to Index Note: We have tried to test all of the code examples but they may contain errors. Any questions, comments, suggestions, or problems should be sent to info@plands.com. |
|
© 2005 Planetary
Data Systems.
All rights reserved. |