Replace substring in string.
Syntax: @replace(str1, str2, str3[, n])
str1: string
str2: string
str3: string
n: (optional) integer
Return: string
Returns the base string str1, with the str3 substituted for the target string str2. By default, all occurrences of str2 will be replaced, but you may provide an optional integer n to specify the maximum number of occurrences to be replaced.
Examples
@replace("Do you think that you can do it?", "you", "I")
returns the string “Do I think that I can do it?”, while
@replace("Do you think that you can do it?", "you", "I", 1)
only replaces the first instance of “you” with “I” so that it returns “Do I think that you can do it?”.
If ALPHA1 is an alpha series,
alpha a1 = @replace(alpha1, "abc", "def")
replaces all instances of “abc” with “def” in ALPHA1 for all observations in the workfile sample.
If AVEC1 and AVEC2 are string vectors,
svector s1 = @replace(avec1, avec2, "abc")
replaces all instances of the strings in AVEC2 with “abc” for each element of AVEC1.
Cross-references