Replace

Description:              This function performs a search and replace operation on a buffer and returns the resulting buffer.

Returns:                    Buffer

Usage:                       Script or Steady State

Format:                      Replace(Buffer, Offset, N, Search, Replace)

Parameters:             Buffer  { text }  { required }  { no default: }

                                      Any text expression giving the buffer to search. The size of the buffer is limited to 65 500 bytes.

                                    Offset  { numeric }  { required }  { no default: }

                                      Any numeric expression giving the buffer offset from 0 to start the search.

                                    N  { numeric }  { required }  { no default: }

                                      Any numeric expression giving the number of buffer characters (bytes) to search.

                                    Search  { text }  { required }  { no default: }

                                      Any text expression giving the search string.  Search must be at least 1 byte long.

                                    Replace  { text }  { required }  { no default: }

                                      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.

                             Since the search and replace strings are delimited by quotation marks, to include a set of quotation marks as part of either, you must use two sets of quotation marks inside of the quotation marks that delimit the string (see the example below).

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 }); 

See Also:

Locate