Functions Index :: S :: StrReplace

[<< up one level]


string :: search


StrReplace(string base, string sought, string rep, int "index", bool "ignorecase", bool "recurse")


A generic substring replacement function that can replace all occurrences of sought inside base with rep or the zero-based index'th specific occurrence.

Both case-sensitive and case-insensitive replacements are supported, controlled by the ignorecase argument.

Also, recursive replacements are supported (where the new string after substitution of sought by rep is searched from the begining for occurence of sought), controlled by the recurse argument.

Notes and conditions on arguments relations:

If recurse is true the rep string must not contain sought as a substring, because this would led to infinite recursion. The function will immediately throw an error if such a condition is detected.


s1 = StrReplace("abbcacbd", "ab", "a", recurse=true)

# s1 == "acacbd"

s2 = StrReplace("abbcacbd", "ab", "a")

# s2 == "abcacbd"

s3 = StrReplace("aBbcabBcaBd", "aB", "A", ignorecase=true, recurse=true)

# s3 == "AcAcAd"

s4 = StrReplace("aBbcabBcaBd", "aB", "A", recurse=true)

# s4 == "AbcabBcAd"


[<< top]