stredit(X;P;N;Y)

Returns a given string, with a specified number of characters starting at a certain position replaced by a given substring.

Syntax

stredit(X;P;N;Y)
bstredit(X;P;N;Y)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

P integer An index corresponding to a particular position in X

The index P is 1-based (i.e., the first character has position 1).

A negative position counts back from the end of the string (i.e., P=-1 refers to the last character).

P=0 refers to the position after the last character of the string X.

If P is N/A, it is treated as 1.

N integer The number of characters to replace in X

N=-1 refers to as many characters as necessary to reach the end of the string.

If N is N/A, it is treated as 0.

Y text Y is the substring to be replaced in X.

A scalar value or the name of a column

Return Value

Returns the text value corresponding to the string X with the N characters beginning at position P replaced with the string Y.

If X is N/A, the result is Y. If Y is N/A, the effect is to delete N characters from X (i.e., replace them with the empty string).

Note: The function will insert or delete characters in X as necessary.

Sample Usage

value position number newstring stredit(value;position;number;newstring)
'testing' 2 1 'oa' 'toasting'
'testing' -3 -1 'er 'tester'
'testing' 1 2 '' 'sting'
'testing' -3 -1 '' 'test'
'testing' 1 0 'con' 'contesting'

Additional Information

  • stredit is Unicode (UTF-8) compliant and will work with Unicode or plain ASCII text fields.
  • If passed a string argument that is not legal Unicode, it will by default signal an error (configurable as a user preference).
  • A corresponding function bstredit can be used with non-Unicode strings (e.g., binary or legacy encodings).