$replace
Search and replace a substring of a string. The search and replace is case-sensitive.
$replace(
Source,
StartPos,
SearchFor,
ReplaceWith {,
Count})
Example: vReplaced = $replace("a should be uppercase", 1, "a", "A", -1)
Parameters
Parameter | Data Type | Description |
---|---|---|
Source | String | String on which the replacement needs to be done |
StartPos | Numeric | Position in Source where the replacement needs to start. |
SearchFor | String | Substring to search for. SearchFor can be a constant string or a syntax string. |
ReplaceWith | String | Substitute for the substring. |
Count | Numeric | Number of occurrences of the substring that should be replaced. If omitted, only the first occurrence of the substring is replaced. If Count is -1, all occurrences are replaced. |
Return Values
String with the replacements made. $replace does not affect $status.
If Source is empty, $replace returns the empty string and an error in $procerror.
If SearchFor is empty, $replace returns the unaltered Source string and an error in $procerror.
Value | Error Constant | Meaning |
---|---|---|
-1118 | <UPROCERR_ARGUMENT>
|
The argument specified is incorrect. |
Use
Allowed in all component types.
Description
Although the Source string can be 2048 MB, using very long Source strings (larger than 50,000 bytes) is not recommended because this can degrade performance.
Using $replace
The following example replaces all occurrences of a with A:
vReplaced = $replace("a should be uppercase", 1, "a", "A", -1) ; Result: vReplaced = "A should be uppercAse"
The following example replaces only the first a:
vReplaced = $replace("a should be replaced by B", 1, "a", "B") ; Result: vReplaced = "B should be replaced by B"
Operation GETXMLITEM
This operation calls an XSLT stylesheet and returns the value of a node in an XML stream. The parameters can specify one node or several nodes.
GETXMLITEM
uses
$replace
to insert parameters
XNODE
and
XVALUE
into an XSLT stylesheet, and uses component
USYSXSLT to process the XSLT stylesheet. For
more information about the XSLT stylesheet used by this operation, and examples
of input and output data, see
USYSXSLT.
operation GETXMLITEM ; Get an item or set of items from an XML stream ; using XPATH patterns. ; Modify an XSLT stylesheet using the $replace ; function, and then activate USYSXSLT. params numeric I_STATUS : OUT string I_STATUSCONTEXT : OUT string I_XML : IN string XNODE : IN string XVALUE : IN string I_VALUE : OUT endparams variables string XSLTFILE endvariables fileload "getitem.xsl", XSLTFILE XSLTFILE = $replace(XSLTFILE, 1, "TargetNode", XNODE) XSLTFILE = $replace(XSLTFILE, 1, "TargetValue", XVALUE) filedump XSLTFILE, "getitemtemp.xsl" activate "USYSXSLT".XMLTRANSFORM(I_XML, "getitemtemp.xsl", " ", I_VALUE, I_STATUS, I_STATUSCONTEXT) end ; operation GETXMLITEM