Replace |
Strings | |
Aptilis 1 |
Replace(String, Target, Replacement)
Replace as its name indicates, replaces occurrences of a target substring with a given replacement.
Return value:
A new string where all the occurences of the target have been replaced.
Example:
a = "John went to buy a hamburger, because he likes ham." $ b = replace(a$, "ham", "cheese") $ print(b$)Result:
John went to buy a cheeseburger, because he likes cheese. |
Note: (especially to C programmers)
The replacement is not done directly in the string given. Instead, a new string is created.
So to replace correctly do:
var = replace(var$, target$, replacement$) $
And not: replace(var$, target$, replacement$)