Replace
| Description: | Performs a case sensitive search and replace operation on a buffer and returns the resulting buffer. |
| Returns: | Buffer |
Usage: ![]() |
Script or steady state. |
| Function Groups: | String and Buffer |
| Related to: | Locate |
Format: ![]() |
Replace(Buffer, Offset, N, Search, Replace) |
| Parameters: |
| Buffer |
| Required. Any text expression giving the buffer to search. The size of the buffer is limited to 65 500 bytes. |
| Offset |
| Required. Any numeric expression giving the buffer offset from 0 to start the search. |
| N |
| Required. Any numeric expression giving the number of buffer characters (bytes) to search. |
| Search |
| Required. Any text expression or array of text expressions, giving the search string(s). Search must be at least 1 byte long. The search is case sensitive. |
| Replace |
|
Required. Any text expression giving the replace string. |
| Comments: |
This function returns a buffer that is the same as Buffer, except that within the first N bytes following Offset, all occurrences of Search are replaced with Replace. |
Example:
If a variable exists such that:
txt = "abcdefABCDEF";
And the following statement is executed:
txt = Replace(txt { Buffer },
0 { Start at beginning of buffer },
12 { Search through 12 characters },
"fA" { Search for this string },
"-wow-" { Replace string with this });
The result will be that txt will contain the string "abcde-wow-BCDEF".
As a further example of how this function is used, if quotation marks were considered illegal characters in a certain context and therefore needed to removed from a string, the following statement could be used to achieve this:
txt = Replace(stringWithQuotes { Search buffer },
0 { Start at beginning },
StrLen(stringWithQuotes) { Search entire string },
"""" { Find all quotes },
"" { Replace with nothing });
